I am learning for a JAVA Programmer I certificate and among questions there is one I can't understand:
//Given:
interface I{}
class A implements I{}
class B extends A {}
class C extends B{}
//and
A a = new A();
B b = new B();
Identify options that will compile and run without error.
A. a = (B)(I)b;
B. b = (B)(I)a;
C. a = (I)b;
D. I i = (C)a;
Now I know that the answer is A) but I don't get it, if the class B is a child of class A, then 'a' can be equal to 'b' without casting, why is the answer B) wrong? What does even casting (B)(I) means?