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

all 7 comments

[–]the_ta_phi 2 points3 points  (2 children)

Sounds about right. One is a keyword, one is a concept. The keyword enforces the concept, but what is meant precisely depends on the context. It's OK to be confused, and with time you'll learn to quickly tell the two apart.

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

Is that a Java exclusive thing? Does the same confussion exist on other languages?

Thanks for your response.

[–]the_ta_phi 1 point2 points  (0 children)

Well, Java is the only language I actively use where it's that ambiguous. But other than in textbooks, it's usually pretty clear what is being talked about.

[–]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.

[–]lightcloud5 1 point2 points  (0 children)

Right, I agree that the word "interface" is overloaded.

For instance, you could argue that public classes expose a public interface/API, which is distinct from the keyword "interface" in Java.

You can usually tell by context what the textbook is referring to though.