aspose file tools*
The moose likes Beginning Java and the fly likes Multiple Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Multiple Inheritance" Watch "Multiple Inheritance" New topic
Author

Multiple Inheritance

lakshmi v.samy
Ranch Hand

Joined: Feb 02, 2006
Posts: 30
Hi friends,

Why java does not multiple inheritance?
I have read so many books,I did not get answer for this question.

Please help me.

Thanks in advance.
Sachin Dimble
Ranch Hand

Joined: Dec 07, 2005
Posts: 100
Hi lakshmi!

Multiple inheritance create a dimond problem (conflict sit.) to avoide this it requires complex logic which is provided by c++. But java avoides this complexity by skiping the multiple inheritance and providing the new solution of interface to achived multiple inheritance...

Hope will help u little....

With Best Regards,
Sachin Dimble.
lakshmi v.samy
Ranch Hand

Joined: Feb 02, 2006
Posts: 30
thanks.please explain in detail.
Thans in advance.
Sachin Dimble
Ranch Hand

Joined: Dec 07, 2005
Posts: 100
Consider a class

class A{}

class B extends A{} //will inherit members of A

class c extends A{} //will inherit members of A
//for multiple inheritance consider

class D extends B,C{}

Now class D will inherit the members of B as well as C but B contains A's members and C too. Now how will D recognise from whome it should inherit the members of A??? The compiler has to maintain this complex relation by creating some complex logic still it's not guranted to eliminate conflict sit.

To reduce this burdon java avoides the multiple inheritance. But surely u can achive same kind of effect by interface!!!

With Best Regards,
Sachin Dimble.
lakshmi v.samy
Ranch Hand

Joined: Feb 02, 2006
Posts: 30
thanks
Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
I have heard of another explanation from somewhere as to why Java does not support multiple inheritance.

It says, that an object can only be an instance of one class i.e. a unique relationship exists between a class and an object. Correct me if I am wrong.


SCJP 1.4 85%
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I think that's not so much "why" but "what happens as a result" of single inheritance. That statement may not be true with other OO languages.

Simplicity was high on the language designer's list of priorities, and they just decided that multiple inheritance was too complex for the developer and the JVM builder. Some folks who grew up with other langauges that have multiple inheritance are disappointed, but it's never bothered me a bit.



A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

You may find this interesting: "multiple inheritance" section from the Thinking in Java interface chapter.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Multiple Inheritance