title: java.lang.ClassException: A cannot be cast into B
body: <p>I implemented this code:</p>
  
  <pre><code>class A {
      //some code
  }
  class B extends A {
      // some code
  }
  
  class C {
      public static void main(String []args)
      {
          B b1 = (B) new A();
          A a1 = (B) new A();
      }
  }
  </code></pre>
  
  <p>Both of these lines, when compiled separately, compile fine,but give runtime error
  with <em><code>java.lang.ClassException: A cannot be cast into B</code>.</em></p>
  
  <p>Why they compile well, but give a runtime error?</p>