title: ClassCastException
body: <p>i have two classes in java as:</p>
  
  <pre><code>class A {
  
   int a=10;
  
   public void sayhello() {
   System.out.println("class A");
   }
  }
  
  class B extends A {
  
   int a=20;
  
   public void sayhello() {
   System.out.println("class B");
   }
  
  }
  
  public class HelloWorld {
      public static void main(String[] args) throws IOException {
  
   B b = (B) new A();
       System.out.println(b.a);
      }
  }
  </code></pre>
  
  <p>at compile time it does not give error, but at runtime it displays an error :
  Exception in thread "main" java.lang.ClassCastException: A cannot be cast to B</p>