2 回答
TA贡献1825条经验 获得超4个赞
你好,标准答案是这样的:
abstract class Animal {
public abstract void eat();
}
class Rabbit extends Animal {
public void eat() {
System.out.println("我吃草");
}
}
class Monkey extends Animal {
public void eat(){
System.out.println("我吃香蕉");
}
}
class Tiger extends Animal {
public void eat(){
System.out.println("我吃肉");
}
}
class Boy{
public void feed(Animal animal){
animal.eat() ;
}
}
public class TestAnimal {
public static void main(String[] args) {
Animal animal1 = new Rabbit() ;
Animal animal2 = new Monkey() ;
Animal animal3 = new Tiger() ;
Boy boy = new Boy() ;
boy.feed(animal1) ;
boy.feed(animal2) ;
boy.feed(animal3) ;
}
}
TA贡献1877条经验 获得超6个赞
abstract class Animal
{ Animal(){
}
public void eat();
}
class monkey extends Animal
{ public void eat()
{System.out.println("我吃香蕉");}
}
classTiger extends Animal
{ public void eat()
{System.out.println(”我吃猴子“);}
}
class boy
{ public static void main(String args[])
{
Aniaml animal1=new monkey();
Aniaml animal2=new Tiger();
animal1.eat();
animal2.eat();
}
}
添加回答
举报