• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

is Java Single inheritance or multiple inheritance

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic