Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interview Question.

 
Shivit Agarwal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
What should we reply to the question.
"Is Multiple Inheritence possible in Java? "

The answer is ovious No. But via interface we achieve this indirectly.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shivit,

technically there is definitely no possibility of multiple inheritance in Java, as you said. Also you're right that you can achieve something similar with implementation of multiple interfaces.
Other languages are in fact using a kind of multiple inheritance for this purpose. There you don't really inherit in the sense of an is-a relationship but inherit from one or more mixin classes. These mixin classes simply add some part of functionality to your actual class like interfaces do in Java. So from that perspective you could say Java in a way uses its own kind of "multiple inheritance" without exposing the risks of using real multiple inheritance incorrectly in languages like C++.

Marco
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to say, I never agree with the idea that interfaces provide a mesaure of multiply inheritance, I just think it complicates matters to think that way.

It is worth noting that Java does indeed support multiply inheritance, of interfaces!

My answer to that question would be:
"Are we talking multiply inheritance of Classes or Interfaces?"

Gavin
 
Shivit Agarwal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic