I implemented this code:
class A {
//some code
}
class B extends A {
// some code
}
class C {
public static void main(String []args)
{
The name it self implies the compiler will just looks at compile-time type of the expression.
It does not do assumptions on the runtime type of the expression.
http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.5.1
Coming to real problem
You cannot cast A to B.You can cast B to A.When you have a Mango,You have Fruit.But when you have a Fruit,It not mean that You have a Mango.