The method reference through "aref" results in Lookup.f being called, but the field reference obtains A.x. The actual class of an object determines which instance method is called. But for fields, the type of the reference is used (here it's aref, of type A). Here is the output. Lookup.f 37
Could anyone explain why this strange behaviour?. Thanks, Anna S Iyer.
Mukesh Rathod
Ranch Hand
Joined: Oct 11, 2000
Posts: 32
posted
0
Its not strange reply. The method invocation is done dynamically in java, not the instance varibale. Hence, when u call a method,the method will be called depending on to which object (class) the reference var. is pointing to, while the varible will be called based on the type of the reference varible. Mukesh