Why does this output: "inside String argument method"? Isn't null "Object" type?
class A {
void printVal(String obj) {
System.out.println("inside String argument method");
}
void printVal(Object obj) {
System.out.println("inside Object argument method");
}
public static void main(String[] args) {
A a = new A();
a.printVal(null);
}
}
The most specific matching method will be called. More information here:
Yes, but null is also String type and all other types, so it selects the most specific method to call.
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