Site Search:

Assessment Test question 1

Question List



Question:

What is the result of executing the following application? (Choose all that apply.)

 
  1 import java.util.concurrent.*;
  2 import java.util.stream.*;
  3 public class test{
  4     public static void await(CyclicBarrier cb) {
  5         try {
  6             cb.await();
  7         } catch (InterruptedException | BrokenBarrierException e) {
  8             //
  9         }
 10     }
 11     public static void main(String...args) {
 12         final CyclicBarrier cb = new CyclicBarrier(3, ()-> System.out.println("Pass!"));  
 13         ExecutorService service = Executors.newScheduledThreadPool(3);
 14         IntStream.iterate(1, i->1) 
 15             .limit(7)
 16             .forEach(i->service.submit(
 17                ()->await(cb)));  
 18         service.shutdown();
 19     }   
 20 }   



Choice:
A. It outputs Pass! once.
B. It outputs Pass! twice.
C. It outputs Pass! three times.
D. The code will not compile because of line 7.
E. The code will not compile because of line 13.
F. The code will not compile because of line 15.
G. The code compiles but throws an exception at runtime. 
H. It compiles but waits forever at runtime.



Next Question