implement or extend?

?

=?ISO-8859-1?Q?Daniel_Sj=F6blom?=

_.-= said:
Hi!

Whats the difference between "implements" and "extends"?

Thanks to all.

-ReAdY-

Well, you implement interfaces and you extend classes. You can only
extend one class in java, but you can implement many interfaces.
 
?

_.-=

Since no one happened to answer my question, I thought I'd answer it myself
now that I've figured it out.

When you "extend" a class, any methods that you write with the same name
will override the parent class' method.

When you "implement" a class, the parent class had nothing more than the
method definition (i.e. there was no code in the method) so, in effect, all
you are doing is adding your own method code to what was just a method
declaration and therefore not overriding the parent methods.

Hope it helps anyone else who was looking for an answer to the same
question.

-EvErEady
 
J

Joona I Palaste

_.-= said:
Since no one happened to answer my question, I thought I'd answer it myself
now that I've figured it out.

"No one happened to answer your question"? Then what do you call the
four answers you got from various people?

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"I will never display my bum in public again."
- Homer Simpson
 
M

Manish Jethani

Joona said:
"No one happened to answer your question"? Then what do you call the
four answers you got from various people?

I think he meant that no one seemed to have given a satisfactory
answer. And after seeing his answer, I think I'll agree. He
gave a more complete answer to his own question.

But Java is now old enough that people will not answer basic
questions like the difference between "implements" and "extends".

Manish
 
R

Roedy Green

Since no one happened to answer my question, I thought I'd answer it myself
now that I've figured it out.

I saw four answers posted before yours. Be careful not to insult the
hand that feeds you.
 
T

Thomas Weidenfeller

Manish Jethani said:
But Java is now old enough that people will not answer basic
questions like the difference between "implements" and "extends".

No, we have a special group for such basic questions:

comp.lang.java.help

/Thomas
 
A

Adam Maass

_.-= said:
Since no one happened to answer my question, I thought I'd answer it myself
now that I've figured it out.

When you "extend" a class, any methods that you write with the same name
will override the parent class' method.

When you "implement" a class, the parent class had nothing more than the
method definition (i.e. there was no code in the method) so, in effect, all
you are doing is adding your own method code to what was just a method
declaration and therefore not overriding the parent methods.

You can't implement a class. You can only implement an interface.

What is an interface? It looks an awful lot like an abstract class where all
the methods are themselves abstract.

-- Adam Maass
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top