因为部分要求没有拍清楚,下面代码供参考,自己可以稍作改动:
public abstract class Animal {
float size;
String breed;
public String eat() {
return "eat";
}
public String roam() {
return "roam";
}
public String makeNoose() {
return "makeNoose";
}
}
Pet接口:
public interface Pet {
public String feed();
public String play();
}
Dog类:
public class Dog extends Animal implements Pet {
public Dog() {
}
public Dog(float s) {
this.size = s;
System.out.print("小花");
}
@Override
public String feed() {
return "feed";
}
@Override
public String play() {
return "play";
}
}
测试类:
public static void main(String[] args) {
Dog dog = new Dog(10);
String feed = dog.feed();
String play = dog.play();
String eat = dog.eat();
String roam = dog.roam();
String makeNoose = dog.makeNoose();
System.out.println("正在" + eat);
System.out.println("size is:" + dog.size);
}
}
运行测试:
追问是放在四个文件里吗