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

Given the code fragments:

class Caller implements Callable {

String str;

public Caller (String s) {this.str=s;}

public String call()throws Exception { return str.concat ("Caller");}

}

class Runner implements Runnable {

String str;

public Runner (String s) {this.str=s;}

public void run () { System.out.println (str.concat ("Runner"));}

}

and

public static void main (String[] args) InterruptedException, ExecutionException {

ExecutorService es = Executors.newFixedThreadPool(2);

Future f1 = es.submit (new Caller ("Call"));

Future f2 = es.submit (new Runner ("Run"));

String str1 = (String) f1.get();

String str2 = (String) f2.get(); //line n1

System.out.println(str1+ ":" + str2);

}

What is the result?

    Correct Answer: A

    The program prints: Run Runner Call Caller : null. Caller uses Callable and returns a String, so f1.get() returns 'Call Caller'. Runner uses Runnable and does not return a value, so f2.get() returns null. The program doesn't terminate because the ExecutorService 'es' is not shut down with es.shutdown().

Discussion
pridemoreOption: A

the program doesnt terminate because there is no call to es.shutdown()

Svetleto13

А,tested

InnovationOption: A

The output is: Run Runner Call Caller : null and the program terminates

WilsonKKerllOption: A

Answer is A. Program doesn't terminate, should call es.shutdown();

InnovationOption: A

The output is: Run Runner Call Caller : null

M_JawadOption: A

the answer is RunRunner CallCaller:null Tested

asdfjhfgjuaDCVOption: A

A is the correct answer

steefaandOption: A

A is correct.

iSnoverOption: A

The answer is A, remember that "Callable" returns a generic type which in this case is a string but "Runnable" always returns null and as the "es" variable of the "Executor Service" type was not finalized with the "es.shutdown" method ()" the program has not terminated

r1muka5Option: A

Correct answer is A.