• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anybody tell me all the advantages of implementing interface over extending class ???
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic