1. x = y This is OK as a super class reference can hold the subclass reference(can refer to the object which subclass was refering) without any explicit cast.
So will pass both the compile time and runtime
test.
2. z =x; require explicit cast.Compilation fails.
3. y = (B)x; x can be casted to y as both A and B are part of same inheritance lineup.Compilation succeds.Runtime fails downcasting not possible.
4. z = (C)y; y can not be casted to z,not in the same inheritance hierarchy.
5. y = (A)y Compilation fails sub class(B) can not hold the reference of super class (A) without a explicit cast. To make it work change something like y = (B)((A)y).