Java OCA OCP Practice Question 708

Question

What is the output of the following?

String[] array = {"A", "B"}; 
List<String> v = Arrays.asList(array); 
v.set(0, "Art"); 
System.out.println(v.contains("Art")); 
  • A. true
  • B. false
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


A.

Note

Since we are creating the list from an array, it is a fixed size.

We are allowed to change elements.

At the end of this code, v is [Art, B].

Therefore, it contains Art, and Option A is correct.




PreviousNext

Related