Java OCA OCP Practice Question 1674

Question

Given the following code:.

public class Main {
  static void print(Object... obj) {
    System.out.println("Object...: " + obj[0]);
  }
  public static void main(String[] args) {
    // (1) INSERT METHOD CALL HERE.
  }
}

Which method call, when inserted at (1), will not result in the following output from the program:.

Object...: 9

Select the one correct answer.

  • (a) print("9", "1", "1");
  • (b) print(9, 1, 1);
  • (c) print(new int[] {9, 1, 1});
  • (d) print(new Integer[] {9, 1, 1});
  • (e) print(new String[] {"9", "1", "1"});
  • (f) print(new Object[] {"9", "1", "1"});


(c)

Note

In (a) and (b), the arguments are elements in the array that is passed to the method.

In (c), the int array is encapsulated as an element in the array that is passed to the method.

Note that int[] is not a subtype of Object[].

In (d), (e), and (f), the argument is a subtype of Object[], and the argument itself is passed without being encapsulated in a new array.




PreviousNext

Related