接口-4

题目:

package homework;

public interface CanSwim {
    
    void swim();

}
package homework;

public interface CanFly {
    
    void fly();

}
package homework;

public abstract class ActionCharacter {
    
    abstract void fight(String emp);
    
    void speak(String s)
    {
        System.out.println(s);
    }
    

}
package homework;

public class Hero extends ActionCharacter implements CanFly, CanSwim {
    
    private String name;
    

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    Hero(String name)
    {
        this.name=name;
    }
    

    @Override
    public void swim() {
        // TODO 自动生成的方法存根
        System.out.println(this.name+"可以游泳");

    }

    @Override
    public void fly() {
        // TODO 自动生成的方法存根
        System.out.println(this.name+"会飞");

    }

    @Override
    void fight(String emp) {
        // TODO 自动生成的方法存根
        System.out.println(emp);

    }

}
package homework;

public class Adventure {

    public static void main(String[] args) {
        
        
        Hero hb=new Hero("张三");
        hb.swim();
        hb.fly();
        
        CanFly cf=new Hero("张三");
        cf.fly();
        
        CanSwim cs=new Hero("张三");
        cs.swim();
        
        ActionCharacter ac=new Hero("张三");
        ac.fight("emp");
        ac.speak("Hello");
        
        
    }

}

运行结果:

posted @ 2016-05-24 14:48  鱼在我这里  阅读(166)  评论(0编辑  收藏  举报