This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
when an instance is type casted, how does it still remains the old object? [ June 24, 2008: Message edited by: gylph knor ]
Joined: Mar 22, 2005
It doesn't matter what it's cast to if afterwards it's assigned to a variable of type "Object". Because that's all the compiler knows about it - that it is an Object. The cast -as it is used here- really does nothing.
The type casting is fine. The real object to which the Object fgh points to is of type wwe which contains the method good(). This is fine as far as the run-time is concerned but for the compiler it checks for the method good() in the Object fgh. Its is clear for the compiler that the method good() is not present in the class Object so you got the error as a result.
Object fgh = (wwe)oi.readObject; fgh.good(); // this fails at compile-time as the compile is interested // only to check fgh(type of Object) contains the method // good or not. Since there in no such method it fails // to compile