28 lines
477 B
Java
28 lines
477 B
Java
interface Animal {
|
|
void makeSound();
|
|
}
|
|
|
|
class Cat implements Animal {
|
|
@Override
|
|
public void makeSound() {
|
|
System.out.println("Meow!");
|
|
}
|
|
}
|
|
|
|
class Cow implements Animal {
|
|
@Override
|
|
public void makeSound() {
|
|
System.out.println("Moo!");
|
|
}
|
|
}
|
|
|
|
public class P3 {
|
|
public static void main(String[] args) {
|
|
Animal cat = new Cat();
|
|
Animal cow = new Cow();
|
|
|
|
cat.makeSound();
|
|
cow.makeSound();
|
|
}
|
|
}
|