<分区>
我刚刚发布了关于抽象方法的帖子,我认为这就是它无法编译的原因。
父类(super class)
public abstract class Monster extends GameCharacter {
public abstract int getxP();
protected int monsterXP;
public Monster(String name, int health, int attack, int xp) {
super(name, health, attack);
this.monsterXP = xp;
}
我的子类
public class Goblin extends Monster {
public Goblin(String name, int health, int attack, int xp){
super(name, health, attack, xp);
}
public Goblin(){
this("Goblin", 70, 15, 2);
}
}
error:Goblin is not abstract and does not override abstract method getxP() in Monster
所以我不确定这里发生了什么,就构造函数而言,父类(super class) GameCharacter 的代码是相同的。我不明白为什么 xp 与名称、生命值和攻击不同。
为了清楚我是如何安排 super 类的
public abstract class GameCharacter {
public abstract String getName();
public abstract int getHealth();
public abstract int getAttackPower();
protected String gameCharacterName;
protected int gameCharacterHealth;
protected int gameCharacterAttack;
public GameCharacter(String name, int health, int attack){
this.gameCharacterName = name;
this.gameCharacterHealth = health;
this.gameCharacterAttack = attack;
}
}