Java SE 8 Programmer II — Question 161

Given the code fragment:
class CallerThread implements Callable<String> {
String str;
public CallerThread(String s) {this.str=s;}
public String call() throws Exception {
return str.concat("Call");
}
}
and
public static void main (String[] args) throws InterruptedException, ExecutionException
{
ExecutorService es = Executors.newFixedThreadPool(4); //line n1
Future f1 = es.submit (newCallerThread("Call"));
String str = f1.get().toString();
System.out.println(str);
}
Which statement is true?

Answer options

Correct answer: B

Explanation

The correct answer is B because the program correctly concatenates the string and prints 'Call Call', and since there is no termination condition, it continues running. Option A is incorrect as the program does not terminate immediately after printing. Options C and D are incorrect because there are no compilation errors or runtime exceptions in the provided code.