public void getData(Object o[]) {
System.out.println("In Side Array");
}
public void getData(Object o) {
System.out.println("In Side Object");
}
public static void main(String[] args) {
new JavaEx().getData(null);
}
Here it's printing Array block why, Why it's not printing Object block?
Both getData
methods can handle a null
argument. In this situation Java tries to choose the method that handles the more specific type.
Now Object
is by definition the superclass of all Java classes, so in this situation Object[]
(which is also an Object
) is the more specific type and getData(Object o[])
is the more specific method. This is why Java chooses this method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With