Oracle
1Z0-809 · Question #6
Given the code fragments: class Caller implements Callable<String> { String str; public Caller (String s) {this.str=s;} public String call() throws Exception { return str.concat ("Caller");} } class…
The correct answer is B. The program terminates after printing: Run Runner Call Caller : Run. You've hit your session limit · resets 5:20pm (America/New_York)
Question
Given the code fragments:
class Caller implements Callable<String> {
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) throws 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(); //line n1
String str2 = (String) f2.get();
System.out.println(str1 +""+ str2);
}
What is the result?
Options
- AThe program prints: Run Runner Call Caller : null And the program does not terminate.
- BThe program terminates after printing: Run Runner Call Caller : Run
- CA compilation error occurs at line n1.
- DAn Execution is thrown at run time.
How the community answered
(42 responses)- A7% (3)
- B76% (32)
- C2% (1)
- D14% (6)
Explanation
You've hit your session limit · resets 5:20pm (America/New_York)
Community Discussion
No community discussion yet for this question.