OCA Java SE 8 Method - OCA Mock Question Method 12


Which of the following compile? (Choose all that apply)

  1. public void A(int... nums) {}
  2. public void B(String values, int... nums) {}
  3. public void C(int... nums, String values) {}
  4. public void D(String... values, int... nums) {}
  5. public void E(String[] values, ...int nums) {}
  6. public void F(String... values, int[] nums) {}
  7. public void G(String[] values, int[] nums) {}


A, B, G.


A and B are correct because the single vararg parameter is the last parameter declared.

G is correct because it doesn't use any vararg parameters.

C and F are incorrect because the vararg parameter is not last.

D is incorrect because two vararg parameters are not allowed in the same method.

E is incorrect because the ... for a vararg must be after the type, not before it.