class A {}
class B extends A {}
class C extends B {}
class D {
void m1(A a) {System.out.print("A");}
void m1(B b) {System.out.print("B");}
void m1(C c) {System.out.print("C");}
public static void main(
String[] args) {
A c1 = new C(); B c2 = new C();
C c3 = new C(); D d1 = new D();
d1.m1(c1); d1.m1(c2); d1.m1(c3);
}}
What is the result of attempting to compile and run the program?
a. Prints: AAA
b. Prints: ABC
c. Prints: CCC
d. Compile-time error
e. Run-time error
f. None of the above
in this eg, we have three overloaded methods in class D.
My q: in case of overloaded methods, in same class or in subclasses, the method call invocation is based on the variable reference type and not the run time reference type of the object instance.
please correct me.