File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Hidden for Instance Variable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Hidden for Instance Variable" Watch "Hidden for Instance Variable" New topic
Author

Hidden for Instance Variable

Anna s Iyer
Greenhorn

Joined: Aug 21, 2000
Posts: 24

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
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
 
 
subject: Hidden for Instance Variable
 
Threads others viewed
Method overriding - special cases:
instance method/static context/dynamic binding
class methods vs instance method
Dynamic Polymorphism: new method in subclass
Nested & Deeply Nested instance
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com