exam questions

Exam 1z0-809 All Questions

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

Exam 1z0-809 topic 1 question 39 discussion

Actual exam question from Oracle's 1z0-809
Question #: 39
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) 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?

  • 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 Execution is thrown at run time.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

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
pridemore
Highly Voted 3 years, 5 months ago
the program doesnt terminate because there is no call to es.shutdown()
upvoted 6 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 3 weeks ago
A is the correct answer
upvoted 1 times
...
steefaand
5 months, 3 weeks ago
Selected Answer: A
A is correct.
upvoted 2 times
...
iSnover
6 months, 1 week ago
Selected Answer: 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
upvoted 2 times
...
r1muka5
1 year, 5 months ago
Correct answer is A.
upvoted 1 times
...
WilsonKKerll
2 years, 4 months ago
Answer is A. Program doesn't terminate, should call es.shutdown();
upvoted 2 times
...
Svetleto13
3 years, 2 months ago
А,tested
upvoted 3 times
...
Innovation
4 years, 6 months ago
The output is: Run Runner Call Caller : null and the program terminates
upvoted 3 times
...
Innovation
4 years, 6 months ago
The output is: Run Runner Call Caller : null
upvoted 2 times
...
M_Jawad
4 years, 6 months ago
the answer is RunRunner CallCaller:null 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