码迷,mamicode.com
首页 > 其他好文 > 详细

完成Adventure中的主方法

时间:2016-05-26 18:48:09      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

package a;

public interface CanSwim {

    void swim();
}
package a;

public interface CanFly {
    void fly();

}
package a;

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

}
package a;

public class Hero extends ActionCharacter implements CanSwim, CanFly {
    private String name;
    
    public String getName() {
        return name;
    }

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

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

    @Override
    public void fly() {
        System.out.println(name+"  飞");

    }

    @Override
    public void swim() {
        System.out.println(name+"  游泳");

    }

    public void fight(String emp) {
        
        System.out.println(name+"  武器"+emp+"  戦斗");
    }

}
package a;

public class Adventure {

    public static void main(String[] args) {
        Hero hb=new Hero("超人");
        hb.swim();
        hb.fly();
        hb.fight("拳头");
        CanFly cf=hb;
        cf.fly();
        CanSwim cs=hb;
        cs.swim();
        ActionCharacter  ac=hb;
        ac.speak("为了正义");
        ac.fight("蛮力");

    }

    
}

技术分享

完成Adventure中的主方法

标签:

原文地址:http://www.cnblogs.com/wenwen123/p/5532056.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!