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

Does Java Support Multiple Inheritance

 
N.Senthil Kumar
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

In Java, Multiple Inheritance is supported by means of Interface. (Correct me if i am Wrong)

class B extends A {}

Now the Class B has A as SuperClass. And Object is the SuperClass for All Java Classes..

then B has A and Object as SuperClass ..

Does it mean Multiple Inheritance. If yes. how it is.

Please Explain me.

Thanks in advance.


 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider below code



it is not a multiple inheritance , it is a multi-level inheritance
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't support multiple inheritance because it makes the code complicated and there were more cons than pros!
http://www.javaworld.com/javaqa/2002-07/02-qa-0719-multinheritance.html

And the example that you gave is a Multi-Level one as clarified by Seetharaman not a multiple one!
 
N.Senthil Kumar
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guys.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
N.Senthil Kumar wrote:Thanks Guys.


You are Welcome
 
Evan Caballero
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only multiple inheritance you can have in java is when implementing interfaces. You can implement not only one inferface, but two, or three, or N.



But this will only modify the behaviour of your objects, not their actual state.
 
april henry
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi N.Senthil Kumar
In java, class doesn't support multiple inheritance but interface does.
Please remember:java supports single inheritance but multi-realization.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49729
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe more accurate to say that interfaces allow Java to mimic multiple inheritance.

And April Henry: you seem to be new: welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic