+ 15
Why it is working like this ?
static void m(Object o){ S.o.p("object")} static void m(String s){ S.o.p("string")} p s v main(String [] args){ m(null) } O/p : string Why not object, even object is null by default ?
7 Respuestas
+ 2
See it is because , while resolving overloaded methods compiler will always give precedence to child type argument than compared with parent type argument
+ 8
If the method with String parameter is removed the o/p is "object".
+ 5
null is not a object here it's a value because it gives null pointer exception if you do like this null.equals("abc"). That's why the o/p is string.
+ 4
Ozair Khan Because there is only one method with object parameter and object can also be null.
When you were using two methods with different parameter then method with String parameter was overloading to method with Object parameter so that time output was string.
+ 4
While resolving overloaded method compiler will always give the precedence for child type argument when compared with parent type argument.
+ 3
Reference objects, such as Strings might have null as their default values.
+ 2
Maybe you can get the same result using arrays.