null can be passed as JavaTest(String arg) , and JavaTest(Object obj) , so the compiler chooses a method with more specific types of arguments. Since String more specific than Object ( String is a subclass of Object ), JavaTest(String arg) is selected.
If you had JavaTest(Integer obj) instead of JavaTest(Object obj) , the compilation would fail, because Integer no more specific than String and String is not more specific than Integer`, so the compiler will not be able to make a choice.
source share