title: Java get runtime class of this?
body: <p>Say I have the following object hierarchy:</p>
  
  <pre><code>public abstract class Animal {
      ...
  }
  
  public class Canine extends Animal {
      ...
  }
  
  public class Feline extends Animal {
      ...
  }
  
  public class Dog extends Canine {
      ...
  }
  
  public class Wolf extends Canine {
      ...
  }
  
  public class Leopard extends Feline {
      ...
  }
  </code></pre>
  
  <p>Let's say the <code>Animal</code> class has a final method that needs to take different actions depending on what the object's runtime type/class is:</p>
  
  <pre><code>public abstract class Animal {
      // Lots of stuff blah blah blah
  
      public final makeNoise() {
          // If we're a Dog, then System.out.println("Woof!");
          // Else if we're a Wolf, then System.out.println("Gggrrrrr!");
          // etc.
      }
  }
  </code></pre>
  
  <p><strong>Here's the kicker:</strong> I <em>know</em> that best practices and OOP would have me write <code>makeNoise()</code> to be an abstract method, and then just implement a different version in each subclass. <strong>However</strong>, for reasons outside the scope of this question, I can't do that.</p>
  
  <p>So, barring best OOP practices, how can I tell - from inside the parent <code>makeNoise()</code> method - what our runtime class is?</p>