This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Jobs Discussion and the fly likes Does JAVA support multiple inheritance or not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Careers » Jobs Discussion
Bookmark "Does JAVA support multiple inheritance or not" Watch "Does JAVA support multiple inheritance or not" New topic
Author

Does JAVA support multiple inheritance or not

James Bellan
Greenhorn

Joined: Nov 05, 2007
Posts: 9
Hi Arulkumaran,

On a specific Interview i have been asked this question and till now i dont have any answers to get this one correctly / perfectly.

Q >> By default every class in Java inherits the "OBJECT" class , so any class is extended by this "OBJECT" class. If i try to extend some other class i think it is extended twice? Is this not multiple inheritance.

Eg: MyClass extends ParentClass (also extends Object class by default).
How this is managed / Or is this exceptional / How does JVM support only this inheritance?

--Naveen.
Don Stadler
Ranch Hand

Joined: Feb 10, 2004
Posts: 451
No, it is not multiple inheritance. It is a chain of single inheritance.

Put it this way: I can write class A which extends Object, Class B which extends A, and Class C which extends B. It's single inheritance all the way.
Dave Hewy
Ranch Hand

Joined: Aug 21, 2003
Posts: 93
Strictly speaking Don is right, you can only specify one class after the extends keyword.

But when you add interfaces into the mix it is possible to engage in multiple "contracts" - similar in many ways to extending several abstract classes that have abstract methods with no implementation.

I've seen many a thread of discussion on Java multiple inheritance !
Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89
I think the answer should be "yes and no"

Java supports multiple inheritance in interfaces but not in implementations.
If asked why no multiple inheritance of implementations, then the answer is simply "simplicity". Java follows the age of C++, but is a stickler for OOP principles. Creators of Java wanted to get rid of the complexity of multiple inheritance (of implementations) that is inherent in C++.

Hope it helps


Sue

SCJP 1.2
SCWCD 1.4
SCBCD 5.0
Mark Herschberg
Sheriff

Joined: Dec 04, 2000
Posts: 6037
Sue's answer is the one I (and most other hiring managers I know) look for when asking that question.

--Mark
James Bellan
Greenhorn

Joined: Nov 05, 2007
Posts: 9
Thanks for all that answers Guys.
I am clear now.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Does JAVA support multiple inheritance or not