Originally posted by Nisheeth Kaushal:
Hi Valentin,
Does the output remains same(i.e. 20) if the "aMethod" method will not be overridden.
And in that case does late binding is possible or not.
Great Going.
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Originally posted by ravish kumar:
[Bcan anyone tell me how compiler knows that he has to do late binding for this method?? [/B]
SCJP2. Please Indent your code using UBB Code
Originally posted by Jose Botella:
The compiler invokes statically, that is, depending on the declared type of the reference the following:
static, private, and constructors invocations.
The methods that are not mentioned in the previous parragraph are invoked dinamically: they are invoked based on the type of the object pointed to by the reference.
There is an especial case: super.method() invocations. With compilers up to Java 1.0.2 the binding was static. With Java 1.0.2 and beyond an especial kind of dinamic binding is performed: at runtime the nearest superclass that defines the method is chosen.
To check this out, use javap -c YourClass to see the JVM instruction that performs the call.
Note that in Java all the methods are bound at runtime, because the compiler produces symbolic references for the invocations of methods and they are resolved only at runtime. In Java, the JVM serves as a linker/optimizer.
SCJP2. Please Indent your code using UBB Code