Assessment Test
-
What is the result of executing the following application? (Choose all that apply.)
import java.util.concurrent.*; import java.util.stream.*; public class BabyPandaBathManager { public static void await(CyclicBarrier cb) { try { cb.await(); } catch (InterruptedException | BrokenBarrierException e) { // Handle exception } } public static void main(String[] args) { final CyclicBarrier cb = new CyclicBarrier(3,()-> System.out.println("Clean!"));// u1 ExecutorService service = Executors.newScheduledThreadPool(2); IntStream.iterate(1, i-> 1) // u2 .limit(12) .forEach(i-> service.submit( // u3 ()-> await(cb))); // u4 service.shutdown(); } }
- It outputs
Clean!
at least once. - It outputs
Clean!
four times. - The code will not compile because of line
u1
. - The code will not compile because of line
u2
. - The code will not compile because of line
u3
. - The code will not compile because of line
u4
. - It compiles but throws an exception at runtime.
- It compiles but waits forever at runtime.
- It outputs
-
What is the result of the following program?
1: public abstract class Message { 2: public String recipient; 3: public abstract final void sendMessage(); 4: public static void main(String[] args) { 5: Message m = new TextMessage(); 6: m.recipient = "1234567890"; 7: m.sendMessage(); 8: } 9: static class TextMessage extends Message { 10: public final void sendMessage() { 11: System.out.println("Text message to " + recipient); 12: } } }
- Text message to null.
- Text message to 1234567890.
- A compiler ...
Get OCP Oracle® Certified Professional Java® SE 8 Programmer II now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.