This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple Inheritance in Java  RSS feed

 
Sujan Reddy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
We all know that JAVA supports OOPS.One of the main concepts in OOPS is Inheritance. Inheritance can be in many forms.One of them is Multiple Inheritance.So JAVA should also support this type of Inheritance.How...? We all also know that JAVA doesn't support it.We can extend a class with only one class.Ofcourse we can implement more than one interface.
My question is what is the secret(is this word OK?) behind this?
I think you have understood my problem.
Anybody...Please clarify my doubt.
Regards
Sujan.
 
Marco Barenkamp
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
consider the following:
You have 3 classes: ClassA, ClassB and ClassC that derives
ClassA and ClassB. Imagine that both ClassA and ClassB do have
a method called 'doSth()'. Now imagine that you create a new
instance of classC and invoke the derived method 'doSth()'. What
method will be performed?
The 'doSth()' method of classA or classB?
This is a problem that will never occur in Java classes because
we do have single inheritance.

------------------
Marco Barenkamp
____________________________________________
L M I N T E R N E T S E R V I C E S AG
Senior Trainer & Architect,
BEA Certified Enterprise Developer
Sun Certified Programmer for the Java2 Platform
Sun Certified Web Component Developer for the Java2 Platform
Sun Certified Developer for the Java 2 Platform
Sun Certified Enterprise Architect for the Java 2 Platform Enterprise Edition (PI)
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many different ways of implementing inheritance, not all of them necessarily desirable in the same language. Java follows after Smalltalk, which implemented only Single inheritance plus a form of "interface" inheritance. (In fact, Smalltalk's a bit complicated to explain in this way since it's an untyped language -- in effect you can send a message to any object and never get a compile time error -- because these are all trapped at runtime. However, the design principles are the same for Java and Smalltalk).
This is different from C++, Java's other "parent" as it were, which implemented multiple inheritance, but had no "interface" inheritance. CLOS had a third type of inheritance, called "delegation". In fact, there is no problem that you can't solve using any of the four languages. The designs may differ, but the outcome will be the same, even though it may take a tiny bit more work to accomplish it in one vs. the other.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing to do with J2EE so I am sending this to... hmmmm... OO, Patterns, etc.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!