I have this code:
class SuperClass {
int method(Object o){
return 1;
}
int method(String s){
return 2;
}
}
public class PassingNull extends SuperClass {
int method(Object s) {
return 3;
}
public static void main(String... a){
SuperClass sc = new SuperClass();
PassingNull sb = new PassingNull();
SuperClass st = new PassingNull();
System.out.println(sc.method(null)); //1
System.out.println(sb.method(null)); //2
System.out.println(st.method(null)); //3
}
}
I understand that for 1 and 3, it prints '2' because that most specific parameter type is called. But not able to understand why 2 prints '2'.