Site Search:

OCPJP Simulation Test 106

<Back to OCPJP





Question: What is the result of the following program?

  1 import java.util.*;
  2 import java.util.concurrent.*;
  3 public class Mix {
  4   public static void main(String[] args) {
  5     List<String> shape = new ArrayList<>(Arrays.asList("circle","square","triangle"));
  6     List<String> collect1 = new CopyOnWriteArrayList<>(shape);
  7     List<String> collect2 = Collections.synchronizedList(shape);
  8     Set<String> collect3 = new ConcurrentSkipListSet<>(shape);
  9     synchronized(new Object()) {
 10       for(String s : collect1) collect1.add("star");
 11       for(String s : collect2) collect2.add("star");
 12       for(String s : collect3) collect3.add("star");
 13       System.out.println(collect1.size()+collect2.size()+collect3.size());
 14     }
 15   }}


Choice:
A. 663
B. 15
C. 666
D. The code does not compile
E. runtime exception at line 10
F. runtime exception at line 11
G. runtime exception at line 12
H. runtime exception at line 13