In java, I have 2 methods which are overloaded and one is main method, so from the main method I call the overloaded method.
public class Test {
public static void main(String[] args) throws IOException {
doSomething(null);
}
private static void doSomething(Object o) {
System.out.println("method with Object in signature is called.");
}
private static void doSomething(String s) {
System.out.println("method with String in the signature is called.");
}
}
Here when I run this java code, it will call the doSomething(String s) method and it will print
method with String in the signature is called.
I think it will call doSomething(Object o) method, but it won't happen.
So can anyone explain to me this in greater detail, why this has happened and how?
Thank you.