食物类,动物类,饲养员类,测试类。实现饲养员给动物喂食物。
食物类: 属性name
动物类: 属性name 方法void eat
饲养员类: 属性name 方法void feed
测试类打印的结果:
张三喂大熊猫
大熊猫吃竹笋
package demo01;
public class Animal {
public String name;
public void eat(){
}
}
package demo01;
public class Feeder {
public String name;
public void feed(){
}
}
package demo01;
public class Food {
public String name;
}
package demo01;
public class Test {
public static void main(String[] args) {
Food f = new Food();
f.name = "竹笋";
Animal a = new Animal();
a.name = "大熊猫";
Feeder fer = new Feeder();
fer.name = "张三";
System.out.println(fer.name+"喂"+a.name);
System.out.println(a.name+"吃"+f.name);
}
}