views:

252

answers:

6

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

A: 

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

fastcodejava
For String, charAt(), indexOf(), etc. -- everything so I could make my own (say) ASCII-only string -- String is final so you're really crippled in what you can do with it. For Date, well, 95% of that class is officially deprecated these days, which suggests to me that a little more implementation flexibility could have been a nice thing. :-)
Ken
+9  A: 

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.

Laurence Gonsalves
Thanks for being more constructive than the other responses. This was far more helpful.
alainmeyer1
+2  A: 

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).

Fabian Steeg
+1  A: 

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.

doppelfish
+1  A: 

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 :)

PatlaDJ
I liked this answer, thank you.
alainmeyer1
"So, better not argue". I disagree :-)
Stephen C
A: 

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?

Epitaph