Untitled
raw download clone
JAVA
views 11
,
size 1064 b
abstract class Role{
protected
     int strength;
     int intelligence;
    abstract double attack();
}




class Warrior extends Role {
    public Warrior(int strength, int intelligence) {
        this.strength = strength;
        this.intelligence = intelligence;
    }
    @Override
    double attack() {
        return strength*1.5;
    }
}




class Mage extends Role {
        public Mage(int strength, int intelligence) {
                this.strength = strength;
                this.intelligence = intelligence;
        }
       @Override
        double attack(){
            return intelligence*2;
        }
}








public class Demo{
    public static void main(String[] args){
        Warrior w = new Warrior(100,60);
        Mage m = new Mage(60,100);
        System.out.println("战士攻击造成的伤害"+w.attack());
        System.out.println("法师攻击造成的伤害"+m.attack());
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.