ashamadelion
ashamadelion

Reputation: 243

Why don't all Java classes have interfaces?

I got this question for homework, and I'm not sure how to answer it. Could you help me out?

Upvotes: 3

Views: 543

Answers (6)

Epitaph
Epitaph

Reputation: 3148

Another way of understanding this question is to look at instances/situations when Interfaces are used. And, ask yourself what repercussions would implementing an Interface has? Consider "Creating Threads" as an example. You can create it by extending the Thread class or by implementing the Runnable interface. Interfaces, in this case, solve the problem of multiple inheritance. What problems would implementing an interface "always" solve/create?

Upvotes: 0

PatlaDJ
PatlaDJ

Reputation: 1249

Answer your teacher that it is because it is pointless every class to have interface. If he asks you "why?", answer him: imagine what would it be if every single man on earth had to have the skills to develop software, the strength to climb mountain peaks, tehnique to run ski, have a solid opinions in political discussions and be able to draw like Picasso... aah.. :) not to mention to speak EVERY LANGUAGE ON EARTH.

I bet there will be people who will argue with me about what's wrong in every person on earth having all those abilities, but that will render our answers off-topic. So, better not argue. At least not here :)

Upvotes: 1

doppelfish
doppelfish

Reputation: 983

We're not here to do your homework. But if you had answered the previous question - as to what interfaces are for - you might answer this question easily.

Upvotes: 1

Fabian Steeg
Fabian Steeg

Reputation: 45754

Perhaps the question aims at the difference between the general concept of an interface to a class or a module and the language construct of a Java Interface (in the sense that all classes do have interfaces, but don't implement an Interface).

Upvotes: 2

Laurence Gonsalves
Laurence Gonsalves

Reputation: 143334

For any kind of "why don't..." question, it's good to think about "what would happen if...". In this case: What would happen if every Java class needed to have an interface? How would it change the existing APIs? How would it change things for people creating new classes? Any problems you find in answering these other questions could be answers to your original question.

Upvotes: 10

fastcodejava
fastcodejava

Reputation: 41127

That will not make any sense. What will be the interface for String or Date?

Upvotes: 0

Related Questions