aspose file tools*
The moose likes Beginning Java and the fly likes Multiple inheritance in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Multiple inheritance in java" Watch "Multiple inheritance in java" New topic
Author

Multiple inheritance in java

Shruthi Sam
Ranch Hand

Joined: Jul 09, 2008
Posts: 73
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

Joined: Oct 27, 2005
Posts: 19718
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Deepika Srivastava
Greenhorn

Joined: Jul 15, 2009
Posts: 5
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


Product Manager at uCertify

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

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

Joined: Jul 09, 2008
Posts: 73
Thank you very much. Now I am clear.
Deepika Srivastava
Greenhorn

Joined: Jul 15, 2009
Posts: 5
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple inheritance in java