• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hidden multiple inheritance in Java ??  RSS feed

 
Hrishikesh Ghatnekar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can be very silly question , but still wanted to ask this..

As we know java doesn�t support multiple inheritance

But
1) All java classes are extended from Object class

2) So what happens when I am extending any child class from a parent class? In such cases theoretically my child class should be extended from Object + bases class

Do is this some kind of hidden multiple inheritance?

Thanks
HG
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right...sort of (only partway). Whether you specify it explictly or not, any class you create is a subclass of Object. So say you do this:



And then you do this:



You're right in saying that Dog is a subclass of Animal and Object. But you're forgetting that what you really wrote was this:



It extends Object whether you say it does or not. So you have:

Object
|
Animal
|
Dog


So Object is Dog's grandparent, and Animal is Dog's parent. In other words, Dog isn't extending from two different parents...you get me? If you want to try to get some benefits of multiple inheritance, look into implementing multiple interfaces...
[ February 03, 2005: Message edited by: Stephen Huey ]
 
Hrishikesh Ghatnekar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stephen for clearing this.


Thanks
HG
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!