public interface Wuqi {
public String useWuqi();
}
public class Jian implements Wuqi{
@Override
public String useWuqi() {
return "用剑";
}
}
public class Quantou implements Wuqi{
@Override
public String useWuqi() {
return "用拳头";
}
}
public class Role {
private Wuqi wuqi;
private String roleName;
public Role(String roleName) {
this.roleName = roleName;
}
public Wuqi getWuqi() {
return wuqi;
}
public void setWuqi(Wuqi wuqi) {
this.wuqi = wuqi;
}
public void fight() {
System.out.println(this.roleName + "_" + wuqi.useWuqi());
}
}
public class AppTest {
public static void main(String[] args) {
Role king = new Role("国王");
king.setWuqi(new Jian());
king.fight();
king.setWuqi(new Quantou());
king.fight();
}
}