This feature of using interface is the powerfull
polymorphism feature in
Java.. It is always advisible to use interface.
Example :
interface Animal{
void bark();
}
class Dog{
void bark(){
//perform bow bow here
}
}
class Cat{}{
void bark(){
//perform mew mew here
}
}
In the main method perform the following ..
Animal animal1 = new Dog();
Animal animal2= new Cat();
animal1.bar(); // bow bow is done for interface object
animal2.bark(); // mew mew is done for interface object