Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


Which method reduces the count in CountDownLatch?

  1. reduce()

  2. decrement()

  3. countDown()

  4. awaitDecrease()

The correct answer is: countDown()

The method that reduces the count in CountDownLatch is called countDown(). This method decrements the count of the latch, which indicates that a task has completed. Option A, reduce(), and option B, decrement(), are not applicable to CountDownLatch. Option A is used to combine values in a stream, while option B is used to decrement the count in a separate type of synchronization object called a semaphore. Option D, awaitDecrease(), is not a valid method in the CountDownLatch class. Therefore, the correct answer is option C, countDown().