Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Does Java allows Multiple Inheritance?  RSS feed

 
sandeep kapse
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone!

I have read that Java doesn't allow Multiple Inheritance. But I have doubt when I think about following scenario :

Say there are two classes A and B. In Java each class by default extends Object class. But You can also do following:



So here we are indirectly extending both Object class as well as B class. This seems like multiple inheritance.

This thing I am not able to understand. So please Can any one explain me?

Thanks.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandeep M, please check your private messages. You can see them by clicking My Private Messages.

To answer your question:

"Multiple inheritance" means inheriting two or more classes at the same level. In your example, class Object and class B are at different levels in the inheritance hierarchy - so this is not multiple inheritance.
[ November 09, 2007: Message edited by: Jesper Young ]
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't allow multiple inheritance in the sense that any class can have only one direct super class.
Of course the entire Object Oriented will be thrown away if that super class couldn't have its own super class, which could have its own super class, etc.

The Java Object inheritance only specifies that the entire class structure is a tree where all nodes have only one parent, whereas the C++ Object inheritance allows multiple paths between the root node and another node.
 
sandeep kapse
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for reminding me of OOP's fundas.
Now I got cleared.

Thank You
- Sandeep.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some more background info: The reason why Java doesn't have multiple inheritance is because you never really need it in practice, and it has some complications such as the diamond problem.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!