Java OCA OCP Practice Question 925

Question

What is the result of the following?

6: String [] names = {"A", "B", "C"}; 
7: List<String> list = names.asList(); 
8: list.set(0, "D"); 
9: System.out.println(names[0]); 
  • A. A
  • B. C
  • C. Compiler error on line 7.
  • D. Compiler error on line 8.
  • E. An exception is thrown.


C.

Note

Converting from an array to an ArrayList uses Arrays.asList(names).

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

If this code were corrected to compile, the answer would be option A.




PreviousNext

Related