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.

34 lines
699 B

abstract class Animal {
public abstract void makesound();
}
interface Swimmable{
void swim();
}
class Dog extends Animal implements Swimmable{
@Override
public void makesound(){
System.out.println("汪汪汪");
}
@Override
public void swim(){
System.out.println("狗刨游泳");
}
}
class Cat extends Animal{
@Override
public void makesound(){
System.out.println("喵喵喵");
}
}
class Main{
public static void main(String[]args){
Animal a =new Dog();
Animal b =new Cat();
a.makesound();
b.makesound();
if (a instanceof Swimmable){
((Swimmable)a).swim();
}
}
}