• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Does Java allows Multiple Inheritance?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 22907
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic