b1.amethod(o); //4
1. Since the declared type of the reference b1 is Base, at compile-time, the class Base is searched for applicable and accessible methods.
There is only one method in Base, amethod(Base b). It is applicable because the argument o of type Over can be assigned to the parameter b of type Base.
2. Here is the way the JLS (15.12.1) describes it:
In all other cases, the qualified name has the form FieldName . Identifier; then the name of the method is the Identifier and the class or interface to search is the declared type of the field named by the FieldName.
3. Here is the way The
Java Programming Language (6.9.1) describes it:
The method resolution process takes place at compile time based on the declared types of the object reference and the argument values. This process determines which form of a method should be invoked, but not which implementation of that method. At run time the actual type of the object the method is invoked upon is used to find an implementation of the method that was determined at compile time.
[ March 11, 2003: Message edited by: Marlene Miller ]