当我们实现某个接口时,必须重写其所有方法,但是一下程序么有实现 CanFight接口的void fight()方法。
interface CanFight {void fight();}
interface CanFly {void fly();}
interface CanSwim {void swim();}
class ActionCharacter {public void fight(){}}
class Hero extends ActionCharacter implements CanFight, CanFly, CanSwim {
@Override
public void swim() {}
@Override
public void fly() { }
}
public class Adventure {
public static void t(CanFight x){x.fight();}
public static void u(CanSwim x){x.swim();}
public static void v(CanFly x){x.fly();}
public static void w(ActionCharacter x){x.fight();}
public static void main(String[] args) {
Hero h = new Hero();
t(h);
u(h);
v(h);
w(h);
}
} |
|