• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple Inheritance

 
lakshmi v.samy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.please explain in detail.
Thans in advance.
 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may find this interesting: "multiple inheritance" section from the Thinking in Java interface chapter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic