看下图实现如下接口和类,并完成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("");
}
}