Hi Piy,
This link (last message) may be perhaps helpfull:
https://coderanch.com/t/242443/java-programmer-SCJP/certification/inheritance I asked myself the same question.
Remember that for method overloading, at compile time, in a call of the form x.f(...) where x is supposed to be of class X, choice of f is determine as follows:
compiler determines
in class X or any superclass of X the signature of the best method f corresponding to the call, what defines in the same time the return type.
So, in your example:
only method m1 of class A is accessible, because c2 is of type A.
If you change the code to the following one, making c2 of type C:
you will get ABC as output, because c2 has now the three overloaded methods at its disposition (by extending B and A, any instance of class C owns these overloaded methods), then the compiler may choose the 'best' one.
More difficult (overloading + overriding):
output: C.A
Explanations:
https://coderanch.com/t/242444/java-programmer-SCJP/certification/overriding-overloading Hope this helps,
Cyril.
SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287