Considering following code.
class B {}
class B1 extends B {}
class B2 extends B {}
public class ExtendsTest{
public static void main(String args[]){
B b = new B();
B1 b1 = new B1();
B2 b2 = new B2();
}
}
Now when you do
b1=(B1)b;
It still compiles even it is obvious that b cannot be case to B1. So why compiler does not give error here.
Instead ClassCastException appears at runtime. Compiler should be more intelligent here.