• 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

Java Doesn't support Multiple inheritance

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

As per I Know Java Doesn't support Multiple inheritance.

By default all the class extends Object class and still we are able to extends one more class to our class.



My Question is Class B had already extended Object class (default) and still able to extend Class A. Is this not Multiple inheritance. ?

Can some explain me clearly. I am little bit confused ?

I knew that Since Class B extend A. Class B cannot extend any other class still java Doesn't support Multiple inheritance.

Thanks,
Sarada
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Say you have two classes -- Class A and Class B. And they both extend from the Object class. Multiple inheritance is the ability to inherit from both class A and class B without making one inherit from the other.



Henry
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can some explain me clearly. I am little bit confused ?


There's nothing to be confused of Just think of the Object class as being a very special class, which is a superclass of all other classes. You don't have to extend it, it's done implicitly. From there, you can extends at most one other class. "Java does not support multiple inheritance" doesn't take into account the very special Object class.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:"Java does not support multiple inheritance" doesn't take into account the very special Object class.



Hmmm. I think that's a somewhat misleading explanation, as the OP might then ask, "But what about this:"



"Doesn't D extend C, B, A, and Object?"

I think the best way to explain it is to simply say that a class can directly extend only one other class. If you drew a diagram of Java inheritance, it always looks like a string of beads, but in C++ (for example) the diagram can look like any acyclic graph.
 
sarada srinivas
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You all mean Java internally support multiple inheritance (Sincemy class has already extended Object class( implicitly) + class A which is multiple inheritance )

But from the developer perspective it resitcts multiple inheritance . Am I right ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ernest wrote:I think the best way to explain it is to simply say that a class can directly extend only one other class.


Thank you for the clarification.

Sarada wrote:But from the developer perspective it resitcts multiple inheritance . Am I right ?


Yes. Check Henry's example about what you cannot do, and Ernest's example about what you can do.
 
sarada srinivas
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you All

My confusion was cleared.

I belive what Christophe said is right

Java does not support multiple inheritance" doesn't take into account the very special Object class.

 
Master Rancher
Posts: 4796
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sarada srinivas wrote:
You all mean Java internally support multiple inheritance (Sincemy class has already extended Object class( implicitly) + class A which is multiple inheritance )

But from the developer perspective it resitcts multiple inheritance . Am I right ?


No - it's not a question of "internally" vs "from the developer perspective". Both Java internals and developers need to understand that if A extends B and B extends C, then A extends C. The question is, what do people mean when they talk about multiple inheritance? From what I've seen, the term is always used to refer to multiple direct inheritance. A inherits directly from B, and B inherits directly from C. A inherits from C, but only indirectly. Each class has exactly one direct parent, except for Object, which has none. Classes may have any number of indirect parents. The thing that is different here between C++ and Java is that C++ allows multiple direct inheritance, and Java does not. So we talk about this difference as "multiple inheritance", and we don't usually bother saying that we mean multiple direct inheritance. Because multiple indirect inheritance was never controversial. We accept it and move on.

Looking back in this thread, I agree with EFH, and disagree with Christophe. The problem is that Christophe makes it sound like multiple inheritance is a special property of the Object class. What EFH is pointing out is that no, multiple indirect inheritance can be a property of any class, and multiple direct inheritance is not possible even with Object. It's a minor point, but I do think Christophe's statement is misleading in this respect.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:The problem is that Christophe makes it sound like multiple inheritance is a special property of the Object class.


I don't know where I made it sound like this. Can you enlighten me on this ?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:

Mike Simmons wrote:The problem is that Christophe makes it sound like multiple inheritance is a special property of the Object class.


I don't know where I made it sound like this. Can you enlighten me on this ?



I don't think you did. From my reading, you simply said that if you don't declare a class as inheriting from anything, then the compiler will automatically have it inherit from the Object class.

The issue is how it was interpreted. Somehow, this became ... Multiple inheritance is not supported, but in the case of the Object class, java does support multiple inheritance. And that is just not correct.

Henry
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know, this:

"Java does not support multiple inheritance" doesn't take into account the very special Object class.


does kind of make things confusing--because it still doesn't support multiple inheritance, whether or not you pay attention to the Object class.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike wrote:The problem is that Christophe makes it sound like multiple inheritance is a special property of the Object class. What EFH is pointing out is that no, multiple indirect inheritance can be a property of any class, and multiple direct inheritance is not possible even with Object. It's a minor point, but I do think Christophe's statement is misleading in this respect.


I had to read this a few times, and after reading Henry's comment, finally understood where the confusion came from. Bad wording can cause a hell of a confusion, sorry about that.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:I don't know, this:

"Java does not support multiple inheritance" doesn't take into account the very special Object class.


does kind of make things confusing--because it still doesn't support multiple inheritance, whether or not you pay attention to the Object class.


Yes, I got it. My bad.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No worries :)
 
Mike Simmons
Master Rancher
Posts: 4796
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
w00t! Glad it was sorted out.
 
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

sarada srinivas wrote:You all mean Java internally support multiple inheritance (Sincemy class has already extended Object class( implicitly) + class A which is multiple inheritance )


I would say this is wrong.

I would says your class does NOT extend the Object class. Your class ONLY extends class A. That's it - nothing else.

However, class A extends the Object class. So since your class is a type A, and A is a type Object, your object has everything a Object does.

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:I would says your class does NOT extend the Object class. Your class ONLY extends class A. That's it - nothing else.


+1
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic