This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

keywords implements and extends

 
vikas motkur
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are the key words different both are used to incorporate inheritance..why is there a difference???
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To put it simply extends is used to inherit other classes both abstract and non-abstract. implements is used in classes to inherit interfaces.
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
implements is used in classes to inherit interfaces


You mean you will provide a legal implementation of the interface so that code outside your class can be sure that certain implementation of methods exist.
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Remko Strating:


You mean you will provide a legal implementation of the interface so that code outside your class can be sure that certain implementation of methods exist.


Yeah, I didn't like that when I wrote it, but couldn't think of a better answer at the time. Not all interfaces have methods defined, so perhaps a better explanation is when a class needs to use the implied contract of an interface.

And if an interface "inherits" another interface, extends is used.

[ August 08, 2007: Message edited by: David McCombs ]
[ August 08, 2007: Message edited by: David McCombs ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic