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.
22 lines
506 B
22 lines
506 B
package org.example;
|
|
|
|
public class AnimalTest {
|
|
public static void main(String[] args) {
|
|
|
|
Animal dog = new Dog("Buddy");
|
|
Animal cat = new Cat("Kitty");
|
|
|
|
dog.makeSound();
|
|
cat.makeSound();
|
|
|
|
if (dog instanceof Swimmable) {
|
|
((Swimmable) dog).swim();
|
|
}
|
|
|
|
if (cat instanceof Swimmable) {
|
|
((Swimmable) cat).swim();
|
|
} else {
|
|
System.out.println(cat.name + " cannot swim.");
|
|
}
|
|
}
|
|
}
|