Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple inheritance in java

 
Shruthi Sam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Deepika Srivastava
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you very much. Now I am clear.
 
Deepika Srivastava
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic