This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Java in General and the fly likes what are the advantages of implementing interface over extending class ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "what are the advantages of implementing interface over extending class ???" Watch "what are the advantages of implementing interface over extending class ???" New topic
Author

what are the advantages of implementing interface over extending class ???

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 761
can anybody tell me all the advantages of implementing interface over extending class ???


Jigar Naik


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44585
    
  34
This goes with your other question.

You can mimic multiple inheritance by implementing several interfaces. The problem with diamond inheritance Jesper Young mentioned doesn't apply if you have two methods with the same signature, if both methods are completely empty.

You can implement several interfaces and only extend one class. An interface provides a set of method headers; any method using your object under the name of its interfaces can rely on those methods being available, particularly if you have implemented them according to the instructions for the interface.

Read the API documentation for Comparable<T> for an example.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what are the advantages of implementing interface over extending class ???
 
It's not a secret anymore!