public class Animal { //创建动物类 类中包含eat方法
public void eat(){
System.out.println("吃东西");
return;
}
}
public interface AnimalInfo {
void fly();
}
public class Bird extends Animal implements AnimalInfo{
public void fly() { //重写 fly 方法
System.out.println("鸟儿飞翔");
return;
}
@Override
public void eat() { //重写 eat 方法
System.out.println("鸟儿吃虫");
}
}
public class Test {
public static void main(String[] args) {
Animal bird1 = new Animal();
bird1.eat();
Animal bird2 = new Bird();
bird2.eat();
AnimalInfo bird3 = new Bird();
bird3.fly();
Bird bird4 = new Bird();
bird4.eat();
bird4.fly();
}
}
标签:fly,eat,void,public,动物,Animal,Bird From: https://www.cnblogs.com/lt3455-/p/18598177