Method Overloading ambiguity

57 views Asked by At

Consider the following code block:

class A {
    static void m(String s) {
        System.out.println("String");
    }

    static void  m(Object o) {
        System.out.println("Object");    
    }

    public static void main(String [] args) {    
        A.m(null);    
    }
}

Here Output is "String" Now my question is that, as Object and String both can accept the null value as both are of Reference type, then why compiler print "String" instead of showing ambiguity error?

0

There are 0 answers