JAVA作业求解答

2024-11-28 03:36:05
推荐回答(2个)
回答1:

/**
* Created by asus on 2019/4/18.
*/
abstract class animalTest {
private String name;
private double weight;

public abstract void feed(int time);

public animalTest(String name, double weight) {
this.name = name;
this.weight = weight;
}
}

class lion extends animalTest{

public lion(String name, double weight) {
super(name, weight);
}

@Override
public void feed(int time) {
System.out.println("狮子每天吃肉"+time+"次。");
}
}

class panda extends animalTest {

public panda(String name, double weight) {
super(name, weight);
}

@Override
public void feed(int time) {
System.out.println("熊猫每天吃竹子"+time+"次。");
}
}

public class animal{
public static void main(String[] args) {
animalTest lion = new lion("辛巴",500);
animalTest panda = new panda("阿宝",300);
lion.feed(3);
panda.feed(4);
}
}

回答2:

我可以帮你写,私聊我发给你吧