aspose file tools*
The moose likes Java in General and the fly likes is Java Single inheritance or multiple inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "is Java Single inheritance or multiple inheritance" Watch "is Java Single inheritance or multiple inheritance" New topic
Author

is Java Single inheritance or multiple inheritance

lakmal vithanage
Greenhorn

Joined: Mar 26, 2012
Posts: 1
In many places, it is mentioned that java is a single inheritance programming language. But we can implements many interfaces to a class and then inheritances from more interfaces.so my problem is whether Java is Single inheritance or multiple inheritance.and please explain why.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Java supports multiple inheritance of interface (or type), which is the main reason to use inheritance in the first place.

It supports only single inheritance of implementation.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11497
    
  16

You can IMPLEMENT many interfaces. But you can only EXTEND one class.

I am not the expert here by any means, but to me, inheritance means "extends". You get stuff for free when you say "public class MyClass extends SomeOtherClass". You get methods.

When you say "public class MyClasss implements SomeInterface, SomeOtherInterface", you don't. You have to then go and implement the methods.

That's how I see the difference.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

fred rosenberger wrote:You can IMPLEMENT many interfaces. But you can only EXTEND one class.

I am not the expert here by any means, but to me, inheritance means "extends". You get stuff for free when you say "public class MyClass extends SomeOtherClass". You get methods.

When you say "public class MyClasss implements SomeInterface, SomeOtherInterface", you don't. You have to then go and implement the methods.

That's how I see the difference.


I don't see it that way.

There's really no fundamental difference between "implements" and "extends". They both specify inheritance, and IS-A relationship. It just so happens that the language designers decided to make a distinction in the keywords used. There's no real difference between extending a purely abstract class and implementing an interface.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11497
    
  16

Jeff Verdegan wrote: There's no real difference between extending a purely abstract class and implementing an interface.

But there is a difference between extending a concrete class and extending an interface. whipping these up (so they may not be 100% correct):





This should compile and run:

This will not:


Because I have to DO something to myClassB. I have to write the code to make this a viable class.

Maybe it is a distinction without a difference. And again, I'm not an expert here. But this is how I see the difference.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

fred rosenberger wrote:
Jeff Verdegan wrote: There's no real difference between extending a purely abstract class and implementing an interface.

But there is a difference between extending a concrete class and extending an interface. whipping these up (so they may not be 100% correct):
...
Maybe it is a distinction without a difference. And again, I'm not an expert here. But this is how I see the difference.


But that extends/implements difference is exactly the same as the difference between extending a concrete class and extending a class with only abstract methods. It's not really a difference between extends and implements, but rather between whether you're inheriting from a concrete type or an abstract type.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is Java Single inheritance or multiple inheritance