标签:
package a; public interface CanSwim { void swim(); }
package a; public interface CanFly { void fly(); }
package a; public abstract class ActionCharacter { public abstract void fight(String emp); public void speak(String s) { System.out.println(s); } }
package a; public class Hero extends ActionCharacter implements CanSwim, CanFly { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public Hero(String name) { super(); this.name = name; } @Override public void fly() { System.out.println(name+" 飞"); } @Override public void swim() { System.out.println(name+" 游泳"); } public void fight(String emp) { System.out.println(name+" 武器"+emp+" 戦斗"); } }
package a; public class Adventure { public static void main(String[] args) { Hero hb=new Hero("超人"); hb.swim(); hb.fly(); hb.fight("拳头"); CanFly cf=hb; cf.fly(); CanSwim cs=hb; cs.swim(); ActionCharacter ac=hb; ac.speak("为了正义"); ac.fight("蛮力"); } }
标签:
原文地址:http://www.cnblogs.com/wenwen123/p/5532056.html