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

Discussion

Which of these correctly declares a method that may be interrupted while waiting?

  • A.void collect() throws Interrupted { latch.await(); }
  • B.void collect() catches InterruptedException { latch.await(); }
  • C.void collect() throws InterruptedException { latch.await(); }
  • D.void collect() { latch.await(); }

Answer: C

await declares InterruptedException, so a caller must either catch it or declare it, and the class is named InterruptedException in full. There is no catches clause in Java; handling happens inside the body with try and catch.

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

Post your comment

Please log in or register to post a comment.