Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface

 
Bharat Kothari
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is purpose of using interfaces rather than allowing multiple inheritance of classes as in C++??
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bharat,
Welcome to JavaRanch!

In C++, you can have two superclasses each containing a method with the same signature. When this happens, how does the subclass know which implementation to inherit? Java gets rid of this sticky situation by only allowing you to extend the implementation of one superclass hierarchy. You can use an interface for any other signatures/contracts you need. Since you supply the implementation, there are no conflicts in this case.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic