程序本来是对了的,但是我想用这种方法用导致有1个错误,我不知道怎么改~~
(不是这道,我想参考这道题这样做~~)
interface Runner{public void run();}
interface Swimmer{public double swim();}
class Animal{ public int eat(){return -1;} }
class Person extends Animal implements Runner,Swimmer{
public void run(){ System.out.println("runing");}
public double swim(){System.out.println("swimming");return -1;}
public int eat(){System.out.println("eating");return -1;}
}
public class TestInterface{
public static void main(String args[]){
TestInterface t=new TestInterface();
Person p=new Person();
t.m1(p);
t.m2(p);
t.m3(p);
}
public void m1(Runner f){f.run();}
public void m2(Swimmer s){s.swim();}
public void m3(Animal a){a.eat();}
}
这道才是~~
interface Flyable{
public void fly();
}
class Bird implements Flyable{
public void fly(){
System.out.println("bird is flying in the air");
}
}
class Plane implements Flyable{
public void fly(){
System.out.println("plane is flying in the air");
}
}
class TestFlyable {
public static void main(String[] args){
TestFlyable a=new TestFlyable;
Bird b=new Bird();
Plane p=new Plane();
a.flying(b);
a.flying(p);
}
public void flying(Flyable f){
f.fly();
}
}