Hi everyone
I was trying to understand how overloading and overriding works when
return type and argument types are objects that are related to each other
Can someone please explain why line number 10 causes a compile error but
line 6 is fine.
The error is line at 17 and says "Reference to out is ambiguous, both
method out(B) in B and method out(A) in C match
If I comment out line 10, the code works fine and results
A.out from B
B.out.
Please explain...
1.class A {
2.public A out (A a) {System.out.println("A.out"); return a;}
3.}
4.class B extends A{
5.public B out (B b) {System.out.println("B.out"); return b;}
6.public A out (A a) {System.out.println("A.out from B"); return a;}
7.}
8.class C extends B{
9.public C out(C c) {System.out.println("main.out"); return c;}
10.public A out (A a) {System.out.println("A.out from C"); return a;}
11.public static void main(
String arg[])
12.{
13.C c = new C();
14.A a = new A();
15.B b = new B();
16.c.out(a);
17.c.out(b);
18.}
19.}