Some people look on interfaces as the ultimate example of the abstract class. An abstract class has some abstract methods and some not abstract. An interface has them all abstract.
The real reason you use interfaces is that you use interfaces. It would be conceivable to have a language without interfaces, but that is not the way
Java was designed. Java is designed with single inheritance, so if you want any more methods you may have to use an interface.
You can call an object an instance of its class, or its superclass, or any of the interfaces it implements.
There are several methods in Java which expect an interface on what they handle. For example the sort() method in the Arrays class expects the Objects it sorts to express the Comparable interface. So your sort method looks for a Comparable object to sort. Comparable means it has to implement the method compareTo(), which returns a negative or positive or zero int, depending on certain rules which are in the API description of Comparable. [It is actually Comparable<T>, but we'll forget the generics for the time being.]
So, what do you do with an interface?
You,
implement a certain number of methods, anduse the name of the interface as a handle so methods can receive it as an argument. Another example: There are several Listener interfaces in the java.awt.event package.
Whenever you do anything to a GUI application, eg move the mouse, push a key, push enter, click a button, an Event object is sent (see the Event types and EventObject), which looks for a Listener. That means you have to have a class which implements the SomethingListener interface.
When the Event object finds a Listener object (ie an object instantiated from a class which implements the WhateverListener interface), it acts as a call to the Listener's somethingHappened() method.
So you need the interface to have the method with the correct signature, and it has to have the name of the interface which the Event looks for.
Yes, the language could have been designed without, but it wasn't. And I think I have probably confused more than helped.
CR
[ April 26, 2006: Message edited by: Campbell Ritchie ]