Tuesday, August 24, 2010

Var-args: DoStuff.java

Courtesy of Sun Web Learning Center

Given:

1. class DoStuff {
2.   public static void main(String [] args) {
3.     doIt(1);
4.     doIt(1,2);
5.   }
6.   // insert code here
7. }

Which three, inserted independently at line 6, will compile? (Choose three.)


A static void doIt(int... x) { }
B static void doIt(int... x, int y) { }
C static void doIt(int... x, int... y) { }
D static void doIt(int... x) { } static void doIt(int x) { }
E static void doIt(int x) { } static void doIt(int x, int y) { }

A, D and E are correct. Options B and C are incorrect because a var-args argument must be a method's last argument.

No comments:

Post a Comment