• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Hidden multiple inheritance in Java ??

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stephen for clearing this.


Thanks
HG
 
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic