I know the automatic type promotion concept in case of primitive data type.But in case of reference data type I have below code which works perfectly.
public class Test4 {
void set(Object o) {
System.out.println("Inside Object");
}
void set(double[] a) {
System.out.println("Array");
}
public static void main(String[] args) {
new Test4().set(null);
}
}
which gives output Array.
But if in place of Object o,if we have any other class then this will show compile time error The method is ambiguous for the type Test4
Below code gives compile time error
public class Test4 {
/*void set(Object o) {
System.out.println("Inside Object");
}*/
void set(String s) {
System.out.println("String");
}
void set(double[] a) {
System.out.println("Array");
}
public static void main(String[] args) {
new Test4().set(null);
}
}
As i know default value of every reference data type (Class,Interface and Array) is null.
So why above code is working in case of Object o.
Thanks in advance