You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

23 lines
611 B

public class AnimalTest {
public static void main(String[] args) {
Animal[] animals = new Animal[2];
animals[0] = new Dog();
animals[1] = new Cat();
for (Animal a : animals) {
a.makeSound();
if (a instanceof Swimmable) {
((Swimmable) a).swim();
}
}
System.out.println("\n--- Testing individual Dog ---");
Dog dog = new Dog();
dog.makeSound();
dog.swim();
System.out.println("\n--- Testing individual Cat ---");
Cat cat = new Cat();
cat.makeSound();
}
}