Java OCA OCP Practice Question 3142

Question

Consider the following program:

import java.util.concurrent.*;
import java.util.*;

public class Main {
        public static void main(String []args) {
               ArrayList<Integer> aList = new CopyOnWriteArrayList<Integer>(); // LINE A
               aList.addAll(Arrays.asList(10, 20, 30, 40));
               System.out.println(aList);
        }//from   w ww  .  j  ava  2s  .co  m
}

Which one of the following options correctly describes the behavior of this program?

  • a) When executed the program prints the following: [10, 20, 30, 40].
  • b) When executed the program prints the following: CopyOnWriteArrayList.class.
  • c) The program does not compile and results in a compiler error in line marked with comment LINE A.
  • d) When executed the program throws a runtime exception ConcurrentModificationException.
  • e) When executed the program throws a runtime exception InvalidOperationException.


c)

Note

The class CopyOnWriteArrayList does not inherit from ArrayList,

so an attempt to assign a CopyOnWriteArrayList to an ArrayList reference will result in a compiler error.




PreviousNext

Related