Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 245

Given the code fragment:

class CallerThread implements Callable {

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?

Call Call and terminates.

    Correct Answer: A

    The program creates a fixed thread pool and submits a Callable task that concatenates the string 'Call' to the initial string provided ('Call'). This results in the printed output being 'CallCall'. However, since the ExecutorService is not explicitly shut down using es.shutdown(), the program does not terminate by itself, resulting in the program printing 'Call Call' and not terminating.

Discussion
DestroyerOption: A

Answer is A

InnovationOption: A

The program prints Call Call and does not terminate. we need to call es.shutdown() at the end of the main for the program to terminate

M_JawadOption: A

The program prints Call Call and does not terminate. Since no shutdown related method of the ExecutorService object is called, the program does not stop execution.

asdfjhfgjuaDCVOption: A

A is the correct answer

steefaandOption: A

A is true.

iSnoverOption: A

Answer is A. The program prints Call Call and does not terminate. We need to call es.shutdown() at the end of the main for the program to terminate