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.
15 lines
381 B
15 lines
381 B
public class TestAnimal {
|
|
public static void main(String[] args) {
|
|
Animal dog = new Dog();
|
|
Animal cat = new Cat();
|
|
|
|
dog.makeSound();
|
|
cat.makeSound();
|
|
|
|
// 向下转型调用游泳方法
|
|
if (dog instanceof Swimmable) {
|
|
Swimmable swimmable = (Swimmable) dog;
|
|
swimmable.swim();
|
|
}
|
|
}
|
|
}
|