title: Check if parent class is instance of child class
body: <p>I have one class defined like this:</p>
  
  <pre><code>class Car {
  
  }
  </code></pre>
  
  <p>And many other defined like this:</p>
  
  <pre><code>class Audi extends Car {
  
  }
  
  class Seat extends Car {
  
  }
  
  class Mercedes extends Car {
  
  }
  
  class Opel extends Car {
  
  }
  
  ...
  </code></pre>
  
  <p>I have a situation where I receive a list of all these cars which is defined like this:</p>
  
  <pre><code>List&lt;Car&gt; cars = new ArrayList&lt;Car&gt;();
  </code></pre>
  
  <p>In that list there are many different cars so how can I find out which one is Audi, which one is Seat etc?</p>
  
  <p>I've tried to do this for cars for which I know they are of type Audi:</p>
  
  <pre><code>Audi audi = (Audi) cars.get(0);
  </code></pre>
  
  <p>This throws <code>ClassCastException</code>. How to handle this situation?</p>