Java OCA OCP Practice Question 953

Question

Given the following method, which of the method calls return 2?

Choose all that apply

public int method(boolean b, boolean... b2) { 
  return b2.length; 
} 
  • A. method();
  • B. method(true);
  • C. method(true, true);
  • D. method(true, true, true);
  • E. method(true, {true});
  • F. method(true, {true, true});
  • G. method(true, new boolean[2]);


D, G.

Note

Option D passes the initial parameter plus two more to turn into a vararg array of size 2.

Option G passes the initial parameter plus an array of size 2.

Option A does not compile because it does not pass the initial parameter.

Options E and F do not compile because they do not declare an array properly.

It should be new boolean[] {true}.

Option B creates a vararg array of size 0 and option C creates a vararg array of size 1.




PreviousNext

Related