Why is the output like this?
- by javatechi
class another {
public void method(Object o) {
System.out.println("This is in method which takes object");
}
public void method(String s) {
System.out.println("This is method which takes string");
}
}
public class NewClass {
public static void main(String args[]) {
another an = new another();
an.method(null);
}
}
When I try to execute this, I get
This is method which takes string
as the output. Why not "This is in method which takes object"? Object can also be null and string can also be null, why doesn't it invoke first method?