Why does this java casting fail : <p>I have three classes.</p>

<p><code>Person &lt;-- Student &lt;-- GradStudent</code>, where <code>&lt;--</code> means extends (ie, GradStudent extends Student, Student extends Person)</p>

<p><code>Person person = new Student(); // this is perfectly legal</code></p>

<pre><code>GradStudent gradStudent = (GradStudent) person;
System.out.println(gradStudent); // java.lang.ClassCastException here
</code></pre>

<p>Why? Our <strong>person</strong> variable is a Student, and we could do <strong>Student s = new GradStudent()</strong>, and so why is this not working?</p>

<p>Similarly if I do</p>

<pre><code>Student student = new Student();
GradStudent aGradStudent = (GradStudent) student;
System.out.println(aGradStudent); // same error here
</code></pre>

<p>Why can we do <strong>Student s = new GradStudent()</strong>, but we cannot do <strong>Student student = new Student()</strong>, and THEN <strong>GradStudent aGradeStudent  = (GradStudent) student</strong></p>
