标签:
package com.homework4; public abstract class ActionCharacter { //声明抽象方法 abstract void fight(String emp); abstract void speak(String s); }
package com.homework4; public interface CanFly { //声明抽象方法 void fly(); }
package com.homework4; public interface CanSwim { //声明抽象方法 void swim(); }
package com.homework4; public class Hero extends ActionCharacter implements CanFly, CanSwim { String name; Hero(String name) { this.name=name; } @Override public void swim() { System.out.println("我是"+this.name+",我会游泳"); } @Override public void fly() { System.out.println("我是"+this.name+",我会飞"); } @Override void fight(String emp) { System.out.println("我是"+this.name+","+emp); } @Override void speak(String s) { System.out.println("我是"+this.name+","+s); } }
package com.homework4; public class E { public static void main(String[] args) { Hero hb = new Hero("张伟"); hb.swim(); hb.fly(); hb.fight("我会降龙十八掌"); CanFly cf = hb; hb.fly(); CanSwim cs = hb; hb.swim(); ActionCharacter ac = hb; ac.speak("我会说一口流利的汉语"); ac.fight("我会黯然销魂掌"); } }
标签:
原文地址:http://www.cnblogs.com/HRZJ/p/5902398.html