• 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

Multiple inheritance in java

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I know java doesn't support multiple inheritance directly and through the interface we can achieve multiple inheritance in java. And we know that all the classes extends the Object class by default. So if we are having a class say x. Let us assume that x extends another class say y. In this scenario x extends y and Object . Is that right? if that is the case is that not a multiple inheritance? Please clarify.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A class only extends Object if no other super class is explicitly given. So y extends Object, but x only extends y, not Object. Yes, x still has Object as a super type, but not as the direct super class.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shruthi Sam wrote:Hi,
I know java doesn't support multiple inheritance directly and through the interface we can achieve multiple inheritance in java. And we know that all the classes extends the Object class by default. So if we are having a class say x. Let us assume that x extends another class say y. In this scenario x extends y and Object . Is that right? if that is the case is that not a multiple inheritance? Please clarify.



heelloooo
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepika Srivastava wrote:

Shruthi Sam wrote:Hi,
I know java doesn't support multiple inheritance directly and through the interface we can achieve multiple inheritance in java. And we know that all the classes extends the Object class by default. So if we are having a class say x. Let us assume that x extends another class say y. In this scenario x extends y and Object . Is that right? if that is the case is that not a multiple inheritance? Please clarify.



heelloooo


What is the meaning of this post? Is it a kick? If so, 14 minutes is much, much too early to warrant it. http://faq.javaranch.com/java/PatienceIsAVirtue
 
Shruthi Sam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much. Now I am clear.
 
Deepika Srivastava
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:

Deepika Srivastava wrote:

Shruthi Sam wrote:Hi,
I know java doesn't support multiple inheritance directly and through the interface we can achieve multiple inheritance in java. And we know that all the classes extends the Object class by default. So if we are having a class say x. Let us assume that x extends another class say y. In this scenario x extends y and Object . Is that right? if that is the case is that not a multiple inheritance? Please clarify.



heelloooo


What is the meaning of this post? Is it a kick? If so, 14 minutes is much, much too early to warrant it. http://faq.javaranch.com/java/PatienceIsAVirtue



Hello Shruthi,

In this scenario, the class X extends the class Object i.e. it is the root of the class hierarchy and every class has Object as a superclass. Here, the class Y extends the class Oject. However, the class X is not extending both classes i.e. class Y and class Object at a same time, the class Object is the superclass of the class X but it is not the direct superclass of X. Hence it is not multiple inheritance.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic