title: Upcast gives ClassCastException
body: <p>Two classes:</p>
  
  <pre><code>public class ClassA implements ClassC {
      private static final long serialVersionUID = 1111111111111111111L;
      public String varA;
  }
  
  public class ClassB extends ClassA implements ClassC {
      private static final long serialVersionUID = 4604935970051141456L;
      public String varB;
  }
  </code></pre>
  
  <p>In my code I have this declaration:
  <code>ClassB classB;</code></p>
  
  <p>and a method </p>
  
  <blockquote>
    <p>myMethod()</p>
  </blockquote>
  
  <p>that returns a <code>ClassA</code> object.</p>
  
  <p>If I write:</p>
  
  <pre><code>classB = (ClassB) myMethod();
  </code></pre>
  
  <p>I thought that I will have:</p>
  
  <pre><code>classB.varA = &lt;a value from myMethod()&gt;
  classB.varB = null
  </code></pre>
  
  <p>but this is not so: I receive a <strong>ClassCastException</strong>.</p>
  
  <p>Why? And how can assign the <code>myMethod()</code> to <code>ClassB</code> in a fast way?</p>