title: How to Check if a class extends another
body: <p>I have seen variants of this question but none of them really address my problem. </p>
  
  <p>Lets say I am building an army with classes. At the top of my Inheritance structure I have an abstract "<strong>Unit</strong>" class. Then an abstract "<strong>Flying</strong>", "<strong>Ground</strong>" and "<strong>Building</strong>" class that extends unit. Then a concrete "<strong>Helicopter</strong>" and "<strong>Jet</strong>" class that extends Flying. As well as a concrete "<strong>Soldier</strong>" and "<strong>Tank</strong>" class that extends Ground. and finally a "<strong>HQ</strong>" and "<strong>Supply</strong>" that extends building. </p>
  
  <p>The following is a method under the "<strong>Soldier</strong>" Class:</p>
  
  <pre><code>public void attack(Unit enemy){
  if(enemy.getSuperclass().equals(Flying)){
      System.out.print("Soldiers cant attack flying units");
  }
  else{
      //Code to attack enemy here
  }
  </code></pre>
  
  <p>I want <i>enemy</i> to be any form of unit. This is because a soldier should be able to attack both buildings and other ground units, However I don't want the Soldiers to be able to attack flying objects.</p>
  
  <p>The obvious problem is that because I declared <i>enemy</i> as a <strong>Unit</strong>, it doesn't know which subclass it belongs to and therefore is trying to find a SuperClass for Unit which doesn't exist. </p>
  
  <p>I'm sure I could have a getter for every unit which has manually set what type of unit it is... but that is more work and doesn't seem efficient. </p>