• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple Inheritance in java  RSS feed

 
abhinas raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i implement multiple inheritance in java using interfaces. if interfaces have some methods having same name then how to distinguish that ?
 
Tim Cooke
Marshal
Posts: 4044
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java supports single inheritance, not multiple inheritance. The example you put forward of multiple interfaces having the same method signature being implemented by a single class is not multiple inheritance.

Have a read through the Oracle Tutorial on Interfaces and Inheritance to learn more about how Java works in this respect.

If you have any further questions once you've read this then please do ask.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If two methods in interfaces have the same signature and different return type: won't compile.
If two methods in interfaces have the same signature and different intent/general contract: logical error/bad design.
If two methods in interfaces have the same signature and same return type and intent: who cares where they come from?.
 
abhinas raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:If two methods in interfaces have the same signature and different return type: won't compile.
If two methods in interfaces have the same signature and different intent/general contract: logical error/bad design.
If two methods in interfaces have the same signature and same return type and intent: who cares where they come from?.



i couldn't understand the meaning of [If two methods in interfaces have the same signature and (different intent/general contract logical error/bad design.] please elaborate it for me
and i want to know the reason why it is happening like this .........
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell, I think he asked about the second scenario you described.
 
abhinas raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yaa i asked about the second scenario. please explain that
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I misunderstood the question.

Fortunately good naming of methods makes that an unusual problem; it is difficult to think of a real‑life example. The intent or general contract is described in the documentation comments, which is why an interface usually consists largely of such comments.That is a particularly daft example, but what is foo going to return? How are you going to count i's bits?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!