How does Java pick which method to call?
Posted
by Gaurav
on Stack Overflow
See other posts from Stack Overflow
or by Gaurav
Published on 2010-05-20T18:18:59Z
Indexed on
2010/05/20
18:40 UTC
Read the original article
Hit count: 262
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?
© Stack Overflow or respective owner