title: Logic behind explicit casting
body: <p>Consider the following classes in Java:</p>
  
  <pre><code>interface I{
  }
  class A implements I{
  }
  
  class B extends A {
  }
  
  class C extends B{
  }
  And the following declarations:
  A a = new A();
  B b = new B();
  </code></pre>
  
  <p>Once you have <code>a = (B)(I) b;</code> the code will compile and run. And don't understand why at all I need to cast into Interface and class B. It would work, in my opinion, when <code>a = b;</code> fine. Can some one explain me the logic of the above explicit casting what make the  code run fine.</p>
  
  <p>But once you have <code>I i = (C) a;</code> it will fail at run-time because 'a' does not point to an object of class C. Why does 'a' needs to point to an object of class C? Besides that I don't get the logic of casting into C class. Anyway you will have reference of I interface. Best regards</p>