15.11.4 Runtime Evaluation of Method Invocation
At run time, method invocation requires five steps. First, a target reference may be computed. Second, the argument expressions are evaluated. Third,
the accessibility of the method to be invoked is checked. Fourth, the actual code for the method to be executed is located. Fifth, a new activation frame
is created, synchronization is performed if necessary, and control is transferred to the method code.
Compile time error
Prints "Parent's method2() Parent's method1()"
Prints "Parent's method2() Child's method1()"
"Prints "Parent's method2() Parent's method1()"" is correct !
15.11.1 Compile-Time Step 1: Determine Class or Interface to Search:
# If the form is MethodName, then there are three subcases:
* If it is a simple name, that is, just an Identifier, then the name of the method is the Identifier and the class or interface to search is the one whose declaration contains the method invocation.
184.108.40.206 Find Methods that are Applicable and Accessible
The class or interface determined by the process described in �15.11.1 is searched for all method declarations applicable to this method invocation; method definitions inherited from superclasses and superinterfaces are included in this search.
The following compile-time information is then associated with the method invocation for use at run time:
* The invocation mode, computed as follows:
o Otherwise, if the compile-time declaration has the private modifier, then the invocation mode is nonvirtual.
220.127.116.11 Compute Target Reference (If Necessary)
o If the MethodName is a simple name, that is, just an Identifier, then there are two subcases:
+ If the invocation mode is static, then there is no target reference.
+ Otherwise, the target reference is the value of this.
18.104.22.168 Locate Method to Invoke
The strategy for method lookup depends on the invocation mode.
If the invocation mode is nonvirtual, overriding is not allowed. Method m of class T is the one to be invoked.
Originally posted by Jose Botella:
private members should not be accessed by public methods