File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

keyword

 
suresh rajaraman
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone please tell the difference between

1. extend and implement

2. class implement an interface
interface implements interface

 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, a class implements an interface because it provides code to implement the methods defined by the interface. A class extends another class because it inherits the implementation of the its superclass, though of course it has the option of modifying the implementation if it chooses to.

An interface can only extend another interface, not implement it? Why? Probably because it doesn't actually implement anything, so extends is a better choice as a keyword.
 
Soumyajit Hazra
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always keep in mind the simple rule. Same type extends but different type implements. So class A want to inherit class B you have to use extends as both are of same type class. If B is interface then different type so implements. If both A and B interface then again same type so extends need to be used.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java tutorial is a good place to start learning about Java.
 
Kr Manish
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Soumyajit Hazra wrote:Always keep in mind the simple rule. Same type extends but different type implements. So class A want to inherit class B you have to use extends as both are of same type class. If B is interface then different type so implements. If both A and B interface then again same type so extends need to be used.

This approach to "remember" is not good for a beginner, or for anyone for that matter ! We should be able to actually understand the meaning of the words than to just "learn by heart" when to use which one.

He should know that "extend" means carrying forward the code that was there originally in the "class" + adding more if required.
And that, "implementing" means providing my own implementation for implemented "interface", since there was not anything to begin with in the interface.
 
Soumyajit Hazra
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He should know that "extend" means carrying forward the code that was there originally in the "class" + adding more if required.
And that, "implementing" means providing my own implementation for implemented "interface", since there was not anything to begin with in the interface.

This concept is already described in Greg's post. Assuming that Suresh reading the post from top to bottom I posted my view.
This approach to "remember" is not good for a beginner, or for anyone for that matter !
Depends on individual. If someone have a real desire to learn thing he/she will keep on asking for reason instead of just seeing a line and remembering it. So the moment I say those words the question arise why? And then comes the explanation part.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47313
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Pedantic mode]You said "keyword" (which is hardly a good thread title), and you said extend and implement. The keywords are extends and implements. That difference may appear trivial, but just try to get it past the compiler [/Pedantic mode]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic