Originally posted by Tony Xu:
Why zero is print out? I think it would be one. As I know, to call a method (which is defined in sub and sup), the most specific method will be called. Why not the member varibles?
Thank you very much.
Hi Tony,
The methods called on an object depend on the actual type of the object itself, not the declared type.
The variables called on on object depend on the declared type of the object regardless of the object's actual type.
The code is returning 0 because that's the value of i in Sup, the declared type of s.
--liz
------------------
Elizabeth Lester
SCJP Dreamin'