Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple inheritance and Multiple Interfaces

 
aakash bhatt
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
When in Java we can multiple interface why not multiple inheritance.
What disadvantages has taken off by removing multiple inheritance and adding
of multiple interfaces.
Regards,
aakash
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One big problem with mulitple inheritance is what to do when both base classes implement a particular method differently. If the subclass doesn't override this method, what code should be called? This situation often arises when both base classes themselves extend from a common ancestor. In this case, a class hierarchy diagram would show a diamond pattern of classes.
This conflict doesn't exist for interfaces, because they don't provide implementations. It is perfectly acceptable for a class to implement two interfaces that define the same method. However, if the interfaces defined methods with identical signatures, but differing return types, there would still be a conflict.
[ February 20, 2003: Message edited by: Greg Charles ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic