What is the output of the following code snippet?.
Callable c = new Callable() { public Object run() {return 10;} }; /*from w ww . j a va 2 s.c o m*/ ExecutorService s = Executors.newScheduledThreadPool(1); for(int i=0; i<10; i++) { Future f = s.submit(c); f.get(); } s.shutdown(); System.out.print("Done!");
B.
The code does not compile because Callable must define a call()
method, not a run()
method, so Option B is the correct answer.
If the code was fixed to use the correct method name, then it would complete without issue, printing Done! at runtime, and Option A would be the correct answer.