Hi,
Originally posted by Ehab Salah:
I understand that the true object type is the one determine which method / variable to be used at run time , is not ?
You are correct except that this is applicable only for methods and not for variables.
When instance variables with same name are defined in both the base and sub class, the one defined in the subclass hides the one defined in the base class. Also variables are resolved by the type of the reference rather than the actual object assigined to the reference.
What i mean here is when you say Base b = new SubClass(); the type of the reference is Base, so b.size prints 100 whereas calling the method getSize() on b causes the subclass getSize to be called since the method is overridden in the subclass.
Hope this helps.
[ June 30, 2005: Message edited by: Reghu Ram T ]
[ June 30, 2005: Message edited by: Reghu Ram T ]
Cheers,<br />Reghu Ram T<br /> <br />SCJP 1.4 - 98 %, SCBCD 1.3 - 94 %, SCMAD 1.0 - 92 %