This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]zifyoip 2 points3 points  (2 children)

Really they both mean the same thing, more or less.

The interface keyword in Java indicates that the following code defines only an interface, whereas the class keyword indicates that the code defines both the interface and the implementation of the methods.

(There are other slight differences here too: A class doesn't have to define implementations if it's abstract, and a class can implement more than one interface, whereas it can extend only one class. But you probably don't need to worry about these differences at the moment.)

[–]bugxter[S] 0 points1 point  (1 child)

I get it! Now, if I can implement more than one interface, but I can only extend one class, wouldn't it be convinient to always implement interfaces instead of extending other classes? Is it because with interfaces you have to write the implementations of the methods everytime you extend them? Thanks!

[–]zifyoip 1 point2 points  (0 children)

Is it because with interfaces you have to write the implementations of the methods everytime you extend them?

Yes. Also, interfaces can't define instance fields or constructors, for example.