public class Test { void doo(Object obj){ System.out.println("object"); } void doo(String s){ System.out.println("string"); } public static void main(String[] args) { new Test().doo(null); } }
null is a literal which is used to give a value to a reference that does not refer to anything.
The compiler has to choose which of those doo() methods to call. Because String is a subclass of Object, String is said to be "more-specific" than object. The compiler will call the doo()method with the most specific formal parameter type. In this case doo(String) rather than doo(Object) will be chosen. -Barry