see this code::
class An {}
class Bn extends An {}
class Cn extends Bn {
static void m(An x, An y) {System.out.print("AA");}
static void m(An x, Bn y) {System.out.print("AB");}
static void m(Bn x, An y) {System.out.print("BA");}
//static void m(Bn x, Bn y) {System.out.print("BB");}
public static void main(
String[] args) {
An a;
Bn b;
m(null,null);
m(a=null,b=null);
m(b, a);
}
}
here in this code when i comment out static void m(Bw x,Bw y)
i get compile time err which says
Cn.java:11: reference to m is ambiguous, both method m(An,Bn) in Cn and method m
(Bn,An) in Cn match
but if i remove the comment code executes well and calls the commented out method where m(null,null) is specified
my question here is how come the compiler know which method to call if null is specified in the method call and is it legal??
plz give simple explaination.