levelのインスタンスからフィールドにアクセスする適切な方法は何Minotaurですか? でエラーを取得しfor (int i =0 ; i < ((Monster) this).level ; i++)ていますCannot cast from Player to Monster。
package player;
import monsters.*;
public class Player extends GameCharacter {
public void performAttackOn(GameCharacter who){
if (who instanceof Monster ){
for (int i =0 ; i < ((Monster) this).level ; i++) { // <<
}
public static class Minotaur extends Monster{ // << nested class which is being created and there is need to access it's level
public Minotaur () {
type = "Minotaur";
}
}
}
package monsters;
public class Monster extends GameCharacter{
public int level = 1;
}
package monsters;
public abstract class GameCharacter{
public static class Minotaur extends Monster{
public Minotaur(){
type = "Minotaur";
hitPoints = 30;
weapon = new Weapon.Sword();
}
}
}
Minotaurから継承されたいくつかのメソッドで拡張monsters.GameCharacterし、monsters.Monsterオーバーライドする必要がありますPlayer.playermonsters.GameCharacter