Possible Duplicate:
What does it mean to “program to an interface”?
Interface vs Abstract Class (general OO)
I'm new to learn JAVA and now I'm confused about interface. I have searched and read many materials but still not clear.
When I try to find some information about interface, I see many people talked about the relationship between interface and abstract class. But I even don't know why they contrast these two. Because I think abstract class is used to tell other people you can not create an object of this abstract class and if you want, you must modify the abstract class. This is something about inheritance, right?
But I don't know the meaning of interface. There is a interface a
, and if a class B
is going to implement the interface a, it must use the reserved word class B implements a
, and then complete all the methods that the interface requires. But my question is, if class B have to complete all the methods by itself, what's the meaning of interface? I think we don't need it.
I don't understand it very much. I read many sentences like: "interface can reflect the core thought of object-oriented language", "interface can help make the program easier" and so on. But I can not really understand the meaning.
So, does anyone can show me some examples to let understand interface? Or you can tell me some useful links or the books that describe the interface clearly. I really hope to figure it out. THANK YOU!