changu mani wrote:During compile time, compiler is not aware of what kind of object ob is pointing to. So it is necessary to do external casting.
Do this way, the compiler error goes away.
Sub ob1= (Sub)ob;
Abc ob2=(Abc)ob;
The first line is legal. The second will give ClassCastException at runtime.