gpt4 book ai didi

java - 方法不是抽象的,也不会覆盖方法

转载 作者:行者123 更新时间:2023-11-29 04:55:13 25 4
gpt4 key购买 nike

<分区>

我刚刚发布了关于抽象方法的帖子,我认为这就是它无法编译的原因。

父类(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;
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com