Possible Duplicate:
Overloaded method selection based on the parameter’s real type
How is an overloaded method choosen when a parameter is the literal null value?
When I execute the code below, I get the following output:
Method with String argument Called …”
Why?
public class StringObjectPOC {
public static void test(Object o) {
System.out.println("Method with Object argument Called ...");
}
public static void test(String str){
System.out.println("Method with String argument Called ...");
}
public static void main(String[] args) {
StringObjectPOC.test(null);
}
}
I tried this:
Test2.class
Test3.class
Test.class
it printed out Test 3
Just like in your scenario, this means that if a method is overloaded (and when null is passed), it recognizes the method which has the child-most parameter.
or in your case: