exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 186 discussion

Actual exam question from Oracle's 1z0-809
Question #: 186
Topic #: 1
[All 1z0-809 Questions]

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();
String str2 = (String) f2.get(); //line n1
System.out.println(str1+ ":" + str2);
es.shutdown();
}
What is the result?

  • A. The program prints: Run Runner Call Caller : null And the program does not terminate.
  • B. The program terminates after printing: Run Runner Call Caller : Run
  • C. A compilation error occurs at line n1.
  • D. An ExecutionException is thrown at run time.
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
DarGrin
5 days, 21 hours ago
The program prints: RunRunner CallCaller:null and terminates. So there is no correct answer.
upvoted 1 times
...
duydn
8 months, 3 weeks ago
Selected Answer: B
B is correct. Program terminates by es.shutdown();
upvoted 1 times
...
WilsonKKerll
2 years, 2 months ago
Answer is B. tested.
upvoted 1 times
...
Svetleto13
3 years ago
B,tested.If we delete es.shutdown(); answer is A.
upvoted 1 times
...
Huim
3 years ago
The program prints: RunRunner CallCaller:null Process finished with exit code 0
upvoted 4 times
...
jduarte
3 years, 1 month ago
Sorry. answer is B.
upvoted 2 times
...
jduarte
3 years, 4 months ago
answer is A but it ends because has es.shutdow();
upvoted 3 times
...
Abdullah_Rahahleah
3 years, 5 months ago
A is the correct answer-tested
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago