• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic