title: Java cast child to parent
body: <p>Class Lion extends Animal.</p>
  <p>Here is my code:</p>
  <pre><code>Animal a = new Animal();
  Lion b = new Lion();
  Animal c = (Animal) b;
  
  Animal[] arr = { a, b, c };
  
  for (int i = 0; i &lt; arr.length; i++) {
      System.out.println(arr[i].getClass().getName());
      arr[i].run();
  }
  </code></pre>
  <p>The result is:</p>
  <blockquote>
  <p>test2.Animal</p>
  <p>Animal Run...</p>
  <p>test2.Lion</p>
  <p>Lion Run...</p>
  <p>test2.Lion</p>
  <p>Lion Run...</p>
  </blockquote>
  <p>From the example seems that &quot;c&quot; is a &quot;Lion&quot;, not an &quot;Animal&quot;. Why is that happening?</p>