my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes compile-time method name resolution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "compile-time method name resolution" Watch "compile-time method name resolution" New topic
Author

compile-time method name resolution

Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
This is not a question.
Back to the basics. I know that the compiler chooses the method ref.m() from the class that is the type of ref. Overriding does not occur at compile-time.

In this example, the compiler chooses method B.run(), A.run(), A.run() in methods m1, m2, m3.
I just thought of another way to see this.

#n is an index into the runtime constant pool of the current class. The runtime constant pool item at that index must be a symbolic reference to a method, which gives the name and descriptor of the method as well as a symbolic reference to the class in which the method is to be found.
9 invokevirtual #4 <Method void run()> // in m1(), #4 == B.run()
9 invokevirtual #5 <Method void run()> // in m2(), #5 == A.run()
9 invokevirtual #5 <Method void run()> // in m3(), #5 == A.run()
[ August 11, 2003: Message edited by: Marlene Miller ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: compile-time method name resolution
 
Similar Threads
iterating over a LinkedList or ArrayList
K&B p.359: JVM point of view
Generic question
rules roundup & general question
Inner class question