I have seen questions on Stack Overflow about a method overloading for null argument but didn't solve my confusion and I tried something different which was not discussed in there answers that's why asking this question.
I want the reason when I pass "null" it executes the function whose argument type is double and when I pass "0" or any other numeric digit like 1,2,10 etc to the function it executes the function whose argument type is "Object". I know there is a difference in NULL and 0 here is the difference.
Thanks!
Code:
public class NullArgumentOverloading {
public static void main(String[] args) {
NullArgumentOverloading obj = new NullArgumentOverloading();
obj.overLoad(null); // prints "Double array argument method."
obj.overLoad(0); // prints "Object o argument method."
}
private void overLoad(Object o) {
System.out.println("Object o argument method.");
}
private void overLoad(double[] dArray) {
System.out.println("Double array argument method.");
}
}