This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
at compile time, the compiler simply checks for existance of refernces. even though ur casting is wrong, at runtime, it is quite possible that the references may point to right type of obects on which the casting operation can go thru. due to the fact that till runtime, jvm cannot determine if the references are pointing to objects that can be cast correctly, the compiler performs a simple check if the references/objects exist.
Hi Pawan, Mnasoor is quite right. At the compile time the object creation just needs the relationship among the classes. Thats is either one is subclass of the other. But at the compile time it seeks that u r doing the right casting or not. Like u r doing the casting of the super to sub or what else.