title: Cannot cast class A to class B
body: <p>What is the proper way to access the field <code>level</code> from instance of <code>Minotaur</code>?
  Getting error in <code>for (int i =0 ; i &lt; ((Monster) this).level ; i++)</code> which is <code>Cannot cast from Player to Monster</code>.</p>
  
  <pre><code>package player;
  
  import monsters.*;
  
  public class Player extends GameCharacter {
  
        public void performAttackOn(GameCharacter who){
  
      if (who instanceof Monster ){
  
          for (int i =0 ; i &lt; ((Monster) this).level ; i++) { // &lt;&lt; 
  
                   }
  
      public static  class Minotaur extends Monster{ // &lt;&lt; nested class which is being created and there is need to access it's level
  
          public Minotaur () {
  
                type = "Minotaur";
  
          }
      }
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>package monsters;
  
  public class Monster extends GameCharacter{
  
      public int level = 1;
  }
  </code></pre>
  
  <hr>
  
  <pre><code>package monsters;
  
  public abstract class GameCharacter{
  
  public static  class Minotaur extends Monster{
  
          public Minotaur(){
              type = "Minotaur";
               hitPoints = 30;
               weapon = new Weapon.Sword();
  
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <p><code>Minotaur</code> should extend <code>monsters.GameCharacter</code>, <code>monsters.Monster</code> and override in <code>Player.player</code> some  methods which was inherited from <code>monsters.GameCharacter</code></p>