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.
 
 
 

32 lines
631 B

// 抽象类 Animal
abstract class Animal {
public abstract void makeSound();
}
// 接口 Swimmable
interface Swimmable {
void swim();
}
// Dog 类继承 Animal 并实现 Swimmable
class Dog extends Animal implements Swimmable {
@Override
public void makeSound() {
System.out.println("狗叫:汪汪汪!");
}
@Override
public void swim() {
System.out.println("狗会游泳,正在狗刨...");
}
}
// Cat 类继承 Animal,不实现 Swimmable
class Cat extends Animal {
@Override
public void makeSound() {
System.out.println("猫叫:喵喵喵~");
}
}