主题:java接口问题 ,急!!!!!!!
为什么我编译的时候提示应在名为Animal.java的文件中声明急急急急急急
public interface Animal {
public void weed ();
public void play();
}
class Farmer implements Animal {
public void weed() {
System.out.println("馒头");
}
public void play() {
System.out.println("皮球");
}
}
class Son implements Animal {
public void weed() {
System.out.println("面包");
}
public void play() {
System.out.println("篮球");
}
}
class F {
Animal a;
F(Animal a) {
this.a = a;
}
public void myPetEnjoy() {
a.weed();
a.play();
}
}
public class PlayAnimal {
public static void main(String args[]) {
Animal A = new Farmer();
Animal S = new Son();
F f = new F(A);
F f1 = new F(S);
f.myPetEnjoy();
f1.myPetEnjoy();
}
}
public interface Animal {
public void weed ();
public void play();
}
class Farmer implements Animal {
public void weed() {
System.out.println("馒头");
}
public void play() {
System.out.println("皮球");
}
}
class Son implements Animal {
public void weed() {
System.out.println("面包");
}
public void play() {
System.out.println("篮球");
}
}
class F {
Animal a;
F(Animal a) {
this.a = a;
}
public void myPetEnjoy() {
a.weed();
a.play();
}
}
public class PlayAnimal {
public static void main(String args[]) {
Animal A = new Farmer();
Animal S = new Son();
F f = new F(A);
F f1 = new F(S);
f.myPetEnjoy();
f1.myPetEnjoy();
}
}