Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Supports Multiple Inheritance without interfaces

 
Akshay Sahu
Greenhorn
Posts: 26
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly this topic has been already discussed here. Your question is answered in that thread.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah how easy was that answer. Never struck to my thoughts
 
Akshay Sahu
Greenhorn
Posts: 26
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So we can conclude by saying Java supports multilevel inheritance but not multiple inheritance.
 
Muhammad Safwat
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the following is an illegal syntax



That is why it is not permitted to extend from multiple classes but you can implement multiple interfaces
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic