Two Laptop Bag*
The moose likes Beginning Java and the fly likes multiple inheritence in core java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

multiple inheritence in core java

karthik Suryanarayanan
Ranch Hand

Joined: Oct 07, 2009
Posts: 110

can anyone clearly explain me about multiple inheritence.., syntactically it is allowed but conceptually it's not.., so please send in u'r replies..,


"Learning is a Culture where your Eagerness & Curiosity plays a major Role".
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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)


[My Blog]
All roads lead to JavaRanch
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18550
    
  40

Multiple inheritence is the ability to extend two unrelated classes. This feature is *not* supported by Java.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
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


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
karthik Suryanarayanan
Ranch Hand

Joined: Oct 07, 2009
Posts: 110

thank you very much ranchers..,
Embla Tingeling
Ranch Hand

Joined: Oct 22, 2009
Posts: 237
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

Joined: May 17, 2010
Posts: 65
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
Sheriff

Joined: Sep 28, 2004
Posts: 18550
    
  40

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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multiple inheritence in core java
 
Similar Threads
Multiple Inheritence in JAVA
Abstract class / Interface
Interface and Abstract
doubts on interface variables
Threads & Inheritence