フリー問題

Java SE 17 Developer のフリー問題 16 / 20 問目

問題文

A task has to compute a value, hand that value back to the code that started it, and it may also report a checked failure. Which interface fits the task, and how does it reach an executor?

選択肢

  1. Callable, because its method returns a value and is declared to throw a checked exception, and an instance of it is passed to the submit method of the executor
  2. Runnable, because an executor takes that interface for its work, so the value has to be kept in a field of the task object and read from there afterwards
  3. Runnable, because its method hands a value back through the Future that submit returns, and a checked exception may be thrown from inside its body as well
  4. Callable, because its method returns a value that the caller wants, and an instance of it is passed to the execute method of the executor

解答・解説を確認するには

正解と解説の確認、回答の記録には無料登録が必要です。登録すると演習モードでフリー問題に回答し、正誤と解説をその場で確認できます。