37.看下图实现如下接口和类,并完成Adventure中的主方法。
//接口Swim
package jieKou;
public interface ICanswim {
void Swim();
}
//接口Fly
package jieKou;
public interface ICanfly {
void Fly();
}
//抽象方法ActionCharacter
package jieKou;
public abstract class ActionCharacter {
abstract void Fight(String emp);
void Speak(String s)
{
System.out.println(s);
}
}
//Hero
package jieKou;
public class Hero extends ActionCharacter implements ICanfly, ICanswim {
private String name;
public Hero(String name) {
super();
this.name = name;
}
@Override
public void Swim() {
System.out.println(name+"游泳");
}
@Override
public void Fly() {
System.out.println(name+"飞");
}
@Override
void Fight(String emp) {
System.out.println(name+emp);
}
}
//主类Adventure
package jieKou;
public class Adventure {
public static void main(String[] args) {
Hero hb=new Hero("宝强");
hb.Fly();
hb.Speak("绿");
hb.Fight("打怪兽");
hb.Swim();
ICanfly cf;
cf=hb;
cf.Fly();
ICanswim cs;
cs=hb;
cs.Swim();
ActionCharacter ac;
ac=hb;
ac.Fight("打小毛驴");
ac.Speak("fuck");
}
}
//运行结果
宝强飞
绿
宝强打怪兽
宝强游泳
宝强飞
宝强游泳
宝强打小毛驴
fuck