Inheritance (Implements)
Lesson 35Author : 🦒
Last Updated : October, 2017
Code
interface Animal{
public void speak();
}
class Cat implements Animal{
@Override
public void speak(){
System.out.println("Meow Meow");
}
}
class Dog implements Animal{
@Override
public void speak(){
System.out.println("Woof Woof");
}
}
public class App{
public static void main(String [] args){
Animal [] animals = {
new Dog(),
new Cat()
};
for(Animal animal : animals){
animal.speak();
}
}
}