package java37;
public abstract class ActionChacrator {
public abstract void fight(String emp);
public abstract void speak(String s);
}
package java37;
public interface CanFly {
public void fly();
}
package java37;
public interface CanSwim {
public void swim();
}
package java37;
public class Hero extends ActionChacrator implements CanFly,CanSwim{
private String name;
public Hero() {
super();
// TODO Auto-generated constructor stub
}
public Hero(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public void fight(String emp) {
// TODO Auto-generated method stub
System.out.println(emp);
System.out.println("战斗");
}
@Override
public void speak(String s) {
// TODO Auto-generated method stub
System.out.println("说话");
}
@Override
public void swim() {
// TODO Auto-generated method stub
System.out.println("游泳");
}
@Override
public void fly() {
// TODO Auto-generated method stub
System.out.println("飞翔");
}
}
package java37;
public class Adventrue {
public static void main(String[] args) {
// TODO Auto-generated method stub
Hero hb = new Hero();
hb.swim();
hb.fight("kk");
hb.fly();
hb.speak("ok");
System.out.println("----------------------");
CanFly cy=hb;
cy.fly();
CanSwim cs=hb;
cs.swim();
ActionChacrator ac=hb;
ac.fight("ko");
ac.speak("ok");
}
}
游泳
kk
战斗
飞翔
说话
----------------------
飞翔
游泳
ko
战斗
说话
接口;抽象类;普通类,没有用对象赋值无法调用方法;