Javac should fail when compiling the testcase below:
== cls1.java ==
package p1;
import p2.cls2;
public class cls1 extends cls2 {
public void method1() {
cls2 c = new cls2();
c.method2(null);
}
}
=== cls2.java ===
package p2;
public class cls2 {
protected void method2(Integer i) {
System.out.println(" Integer");
}
public void method2(String s) {
System.out.println(" String");
}
}
Actually both method2()'s are accessible and none of them is more specific than
another one.
So, the reference to c.method2(null) in cls1.cls1() is ambiguous.
!!! Please note that if the super.method2(null) is written instead of
c.method2(null) in cls1.cls1() javac issues an error about the ambiguous
reference to cls2.method2().
== cls1.java ==
package p1;
import p2.cls2;
public class cls1 extends cls2 {
public void method1() {
cls2 c = new cls2();
c.method2(null);
}
}
=== cls2.java ===
package p2;
public class cls2 {
protected void method2(Integer i) {
System.out.println(" Integer");
}
public void method2(String s) {
System.out.println(" String");
}
}
Actually both method2()'s are accessible and none of them is more specific than
another one.
So, the reference to c.method2(null) in cls1.cls1() is ambiguous.
!!! Please note that if the super.method2(null) is written instead of
c.method2(null) in cls1.cls1() javac issues an error about the ambiguous
reference to cls2.method2().