不同的是定义一个抽象类先
//抽象类
public abstract class interface4 {
public abstract void fly();
public abstract void eat();
}
//定义老鹰类继承
/定义一个老鹰类
public class interface3 extends interface4{
public void fly(){
System.out.println(“我是老鹰,我会飞”);
}
public void eat(){
System.out.println(“我是老鹰,我吃兔子”);
}
}
定义麻雀类继承
//定义一个麻雀类
class interface2 extends interface4{
public void fly(){
System.out.println(“我是麻雀,我会飞”);
}
public void eat(){
System.out.println(“我是麻雀,我吃虫子”);
}
}
定义鸵鸟类继承
//定义鸵鸟
class interface1 extends interface4 {
public void fly(){
System.out.println(“我是鸵鸟,我不会飞”);
}
public void eat(){
System.out.println(“我是鸵鸟,我吃土”);
}
}
定义测试类
public class test01 {
public static void main(String[] args){
interface3 laoying =new interface3();
laoying.fly();
interface1 tuoniao=new interface1();
tuoniao.fly();
}
}