| 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
Bartender
Joined: Sep 08, 2007
Posts: 2946
|
|
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: 2216
|
|
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
Bartender
Joined: Aug 22, 2010
Posts: 2384
|
|
|
Exactly this topic has been already discussed here. Your question is answered in that thread.
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2946
|
|
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/
|
 |
 |
|
|
subject: Java Supports Multiple Inheritance without interfaces
|
|
|