This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

multiple inheritence in core java

 
karthik Suryanarayanan
Ranch Hand
Posts: 121
Java Opera Oracle
  • Mark post as helpful
  • send pies
  • Report post to moderator
can anyone clearly explain me about multiple inheritence.., syntactically it is allowed but conceptually it's not.., so please send in u'r replies..,
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi, welcome to the ranch

The next time you want to post, please use real words.

(I'm moving this thread to a more appropriate forum)
 
Henry Wong
author
Marshal
Pie
Posts: 21362
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Multiple inheritence is the ability to extend two unrelated classes. This feature is *not* supported by Java.

Henry
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Report post to moderator
Java supports only Multilevel inheritance not multiple inheritance.

Multilevel -A class extend only one class directly but its super class can extend another class and so on.In java every class is a child class of class called Object.

Multiple-A class can extend more than one class directly.
Multilevel:

class A
class B extends A
class C extends B

Multiple:

class A
class B
class C extends A,B
 
karthik Suryanarayanan
Ranch Hand
Posts: 121
Java Opera Oracle
  • Mark post as helpful
  • send pies
  • Report post to moderator
thank you very much ranchers..,
 
Embla Tingeling
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Report post to moderator
karthik rsn wrote:can anyone clearly explain me about multiple inheritence.., syntactically it is allowed but conceptually it's not.., so please send in u'r replies..,


Both a class and an interface represents a type. The difference is that a class can carry implementation but an interface cannot.

Now the Java inheritance model supports multiple inheritance of type but only single inheritance of implementation. So Java allows a class to inherit one class at the most but an unlimited number of interfaces. An interface can inherit an unlimited number of interfaces.

In OO design the inheritance of type is considered most important and here Java imposes no restrictions. Java supports multiple inheritance of type.

When it comes to inheritance of implementation Java imposes a restriction. At the most one implementation can be inherited. The reason for this limitation, given in the Java Programming Language by Gosling and others, is problems associated with so called diamond inheritance.

In practice multiple inheritance of implementation, although not supported by Java, can be simulated. This is done by splitting up the class to be inherited into one interface that's inherited and one implementation class that's delegated. The only drawback is that it requires more writing.

So in summary, Java supports multiple inheritance of type, the most important form of inheritance in OO design. Java supports single inheritance of implementation only, but multiple inheritance of implementation can easily be simulated.
 
Mohnish Khiani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Report post to moderator
is there a technical answer as to why multiple inheritence is removed fron java.....the diamond problem is still possible through interfaces...so why didn't they remove multiple inheritence through interfaces?
 
Henry Wong
author
Marshal
Pie
Posts: 21362
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Mohnish Khiani wrote:is there a technical answer as to why multiple inheritence is removed fron java.....the diamond problem is still possible through interfaces...so why didn't they remove multiple inheritence through interfaces?


As already answered in the other topic that you bumped -- having the ability to form a diamond doesn't mean that it is a "diamond problem".

And please don't bump multiple topics -- one should be enough.

Henry

 
    Bookmark Topic Watch Topic
  • New Topic