Multiple choice java

Which, inserted independently at line 6, will compile? (Choose all that apply.)

  1. static void doStuff(int... doArgs) { }

  2. static void doStuff(int x, int... doArgs) { }

  3. static void doStuff(int[] doArgs) { }

  4. static void doStuff(int... doArgs, int y) { }

Reveal answer Fill a bubble to check yourself
A,B Correct answer
Explanation

In Java, varargs (int...) must be the last parameter in a method signature. Option A is a simple varargs parameter - valid. Option B has a required parameter before varargs - valid because varargs is still last. Option C uses array syntax instead of varargs - syntactically valid but different semantics (would not match a varargs call in overloading). Option D is invalid because varargs cannot be followed by another parameter.