This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Java Supports Multiple Inheritance without interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Supports Multiple Inheritance without interfaces" Watch "Java Supports Multiple Inheritance without interfaces" New topic
Author

Java Supports Multiple Inheritance without interfaces

Akshay Sahu
Greenhorn

Joined: Sep 04, 2009
Posts: 26

Hi everyone !

My name is Akshay Sahu and I have a serious issue on my mind.

I say "Java supports multiple inheritance" and I came to this conclusion based on the following points:

1. Every class in java inherits itself and the java.lang.Object class. (Reference Kathy Sierra and Bert Bates OCJP 6). This statement alone is enough to prove it.

2. And if we extend another class, say java.lang.Thread, then clearly your class is said to be implementing Multiple Inheritance.

Then why does, Oracle (formerly SUN) say that, Java does not support Multiple Inheritance.

Please provide a solution to this at the earliest.

Thank You,
Akshay Sahu.


Akshay Sahu
OCBCD (EJB 3), OCJP (Java SE 6), MCTS (MS SQL Server 2005)
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

I was shocked to see the Subject of this post! Anyways I dont know how to explain. May be other Ranchers will be able to add relevant information.

The whole idea of not allowing multiple inheritance was to avoid the Deadly Diamond of death. But in the query raised by you I dont see any kind of such violation. And with overriding and Polymorphism, the JVM will know which method to call even if the particular Class extends Thread and it in turn Object (and Object contains fixed number of methods).


Mohamed Sanaulla | My Blog
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Howdy, Akshay!

Well champ, there is no multiple inheritance!

2. And if we extend another class, say java.lang.Thread, then clearly your class is said to be implementing Multiple Inheritance.


I think you are saying this because you have the feeling that you are extending Thread and Object, right? Well, the thing is, you are only extending Thread, and Thread extends Object. So it is indeed possible to only extend one class, and thus no multiple inheritance.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Exactly this topic has been already discussed here. Your question is answered in that thread.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

Ah how easy was that answer. Never struck to my thoughts
Akshay Sahu
Greenhorn

Joined: Sep 04, 2009
Posts: 26

Hi everyone !!!

I have got my answers after I discussed the above issue with my colleague.

The explanation is as follows:

1. A class extending itself is called as Cyclic Inheritance. And no OO programming language in this world supports Cyclic Inheritance.
2. In Kathy's book, it was written as "Other than objects of class Object, all java objects are polymorphic as they pass the IS-A test for their own type and for the Object class".
3. And when you extend, say java.lang.Thread class, then your class does not extend Object, they extend Thread which in turn extends Object. This becomes Multi-level inheritance instead of multiple inheritance.



Thank You,
Akshay Sahu.
ankita kataria
Greenhorn

Joined: Nov 09, 2010
Posts: 1
Hi Akshay,

If your class is extending Thread Class then the Object class automatically comes in the hierarchy,so it won't be multiple inheritance but multi-level inheritance.
Your class extending Thread which in turn extending Object.

Hope it clears your doubt
Soumyajit Hazra
Ranch Hand

Joined: Jun 26, 2007
Posts: 136
So we can conclude by saying Java supports multilevel inheritance but not multiple inheritance.


Java Programmer | SCJP 1.5 | SCWCD 1.4
Muhammad Safwat
Greenhorn

Joined: Aug 12, 2008
Posts: 12

the following is an illegal syntax



That is why it is not permitted to extend from multiple classes but you can implement multiple interfaces


http://www.thejavacode.com/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Supports Multiple Inheritance without interfaces
 
Similar Threads
Does Java Support Multiple Inheritance
Architecture of EJB3
multiple inheritance
Multiple inheritance in java
multiplt inheritence in java