OCA Java SE 8 Core Java APIs - OCA Mock Question Core Java APIs 3-4








Question

What is the result of the following?

     1: String [] names = {"A", "B", "C"}; 
     2: List<String> list = names.asList(); 
     3: list.set(0, "Z"); 
     4: System.out.println(names[0]); 
  1. Z
  2. A
  3. Compiler error on line 2.
  4. Compiler error on line 3.
  5. An exception is thrown.




Answer



C.

Note

Arrays.asList(names) converts an array to an ArrayList uses.

There is no asList() method on an array instance.