JAVA小练习54——方法的重写

    xiaoxiao2022-07-03  119

    //动物 大类型 class Animal{ } //鱼 class Fish extends Animal{ } //父类 class Fu{ String name; public Fu(String name){ this.name = name; } public Animal eat() { System.out.println(name+"吃番薯..."); return new Animal(); } } //子类 class Zi extends Fu{ public Zi(String name){ super(name); //调用父类一个参数 的构造函数 } //方法的重写 public Animal eat() { System.out.println(name+"吃点开胃菜.."); System.out.println(name+"喝点汤..."); System.out.println(name+"吃点龙虾..."); System.out.println(name+"吃点鲍鱼..."); System.out.println(name+"喝点酒..."); System.out.println(name+"喝糖水..."); return new Animal(); } } class Demo54 { public static void main(String[] args) { Zi zi = new Zi("大头儿子"); zi.eat(); } }
    最新回复(0)