... well, i will explain you with an example...
Suppose I create an interface, named Vehicle, that define the behavior that the clases implement it, could have.
public interface Vehicle{
void openDoors();
void turnOn();
// more methods
}
Then I write a documentation, explaining that the methods should do. In the 'openDoors()' method, I say: 'this method is optional', because there are vehicles, that doesn�t have doors
Now, you create two clases, implementing the interface: 'Car' and 'Bike'
public class Car implements Vehicle{
void openDoors(){
//some stuff here
}
void turnOn(){
//some stuff here
}
}
public class Bike implements Vehicle{
void openDoors(){
throw new UnsupportedOperationException();
}
void turnOn(){
//some stuff here
}
}
In the Bike class, the method 'openDoors()', heve no sense, since the bikes have no doors. But because the Java languaje rules, you have to implement every method of the interface, so in the Bike class you throws an exception, while in the Car class, does something.