How does Java pick which method to call?
- by Gaurav
Given the following code:
public class Test {
public void method(Object o){
System.out.println("object");
}
public void method(String s) {
System.out.println("String");
}
public void method() {
System.out.println("blank");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Test test=new Test();
test.method(null);
}
}
Java prints "String". Why is this the case?