title: How to check if child object is from specific class (and not parent) (Java)
body: <p>I have to write a small text-based game for school in which I have a Player class and a Computer class. In the Game class I need to differentiate between these two classes so I can print instructions ONLY when the player is not a computer.</p>
  
  <pre><code>public class Player {
      private String name;
  
      public Player(String name) {
          this.name = name;
      }
  }
  
  public class Computer extends Player {
      public Computer(String name) {
          super(name);
      }
  }
  </code></pre>
  
  <p>I've tried the following:</p>
  
  <pre><code>player1 = new Player;
  
  if(player1.getClass() != Computer.class) {
      System.out.println("Your turn, player 1.");
  }
  </code></pre>
  
  <p>This should print "Your turn, player 1." because a player is not a computer, right? Well it doesn't and I have no idea how to do it otherwise.</p>
  
  <p>I have tried instanceof, but that always returns true because Computer is an instance of Player.</p>
  
  <p>Help would be very much appreciated!</p>
  
  <p>~ Daan</p>