Hi all,
When you reference instance variables, the
declared type of the object reference is used. In the example, the declared type of the object reference variable <code>tins</code> is <code>t1</code> so '2' is printed.
When you call methods, the
runtime type is used. In the example, the runtime type is <code>t2</code>. <code>amethod()</code> in class <code>t2</code> is called, and as there is an instance variable <code>i</code> in <code>t2</code>, '3' is printed.
See
JLS §15.11 Field Expressions Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform