首页 > 代码库 > Java基础-接口看下图实现如下接口和类,并完成Adventure中的主方法

Java基础-接口看下图实现如下接口和类,并完成Adventure中的主方法

技术分享

技术分享

 

package hanqi;public interface CanSwim {    void swim();}
package hanqi;public interface CanFly {        public void fly();}
package hanqi;public abstract class ActionCharacter {      abstract void fight(String emp);              abstract void speak(String s);    }
package hanqi;public class Hero  extends ActionCharacter implements CanFly, CanSwim{     String name;        Hero(String name)        {            this.name=name;        }                public void swim() {            System.out.println(this.name+",游泳");        }        public void fly() {            System.out.println(this.name+",飞");        }        void fight(String emp) {            System.out.println(this.name+","+emp);        }        void speak(String s) {            System.out.println(this.name+","+s);            }}
package hanqi;public class Adventure {    public static void main(String[] args) {        // TODO 自动生成的方法存根                Hero hb = new Hero("A");        hb.swim();        hb.fight("B");        hb.fly();                CanFly cf = hb;        hb.fly();                CanSwim cs = hb;        hb.swim();                        ActionCharacter ac = hb;        ac.speak("C");        ac.fight("D");                    }}

 

 技术分享

 

Java基础-接口看下图实现如下接口和类,并完成Adventure中的主方法