Monday, September 22, 2014
varargs
public class VarargsTest {
public void methodA(String str, Integer... is){
System.out.println("first methodA called");
}
public void methodA(String str, String... strs){
System.out.println("second methodA called");
}
public static void main(String[] args){
VarargsTest vt = new VarargsTest();
vt.methodA("USA", 0);
vt.methodA("USA", "People");
//vt.methodA("USA"); // compile error. compiler does not know which methodA to invoke
//vt.methodA("USA", null); // compile error. null is not any type. compiler does not know which methodA to invoke
}
}
OUTPUT
first methodA called
second methodA called
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment