Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which one of the following statements about Callable compared with Runnable is true?

  • A.A Callable can return a value and throw a checked exception; a Runnable can do neither.
  • B.A Runnable can return a value and throw a checked exception; a Callable can do neither.
  • C.Both can return a value, but only Runnable may throw a checked exception.
  • D.Both are identical apart from the name of their single method.

Answer: A

Runnable.run() returns void and declares no checked exception, so a task that produces a result or fails has nowhere to put either. Callable.call() returns a value and is declared to throw Exception, which is why an ExecutorService hands back a Future that can deliver a result or rethrow the failure.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.