Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

interface  RSS feed

 
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
Sheriff
Posts: 37242
519
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!