OK: tq is a TestQ48 which does not have an echoN method. But we know that tq really refers to an object of type DerivedQ48 which does have an echoN method. The downcast is OK an compiletime and runtime.
As for the parameter: the object has two paramA members: one in the superclass TestQ48 part and another in the DerivedQ48 part.
tq.paramA is the value (9) of the paramA in the superclass part. And that's what gets printed by the echoN method. [ May 01, 2007: Message edited by: Barry Gaunt ]
M Krishnan wrote How come it is 9 and not 3 eventhough tq is pointing to DerivedQ48 ?
variable refered depends on Reference Type (prints 9) methods that can be called depends on Reference Type (To call echoN cast was necessary) method called at runtime depends on the Object Type. [ May 01, 2007: Message edited by: swarna dasa ]
Joined: Feb 28, 2007
Thanks Keith and Barry for time prompt and fantastic reply.
BTW Krishnan, Member variables don't come under polymorphic call.
Meena R. Krishnan
Joined: Aug 13, 2006
>>BTW Krishnan, Member variables don't come under polymorphic call. Yes,yes. I wasn't awake while typing that and "tq." before paramA tricked me.