Multiple choice

Which of the following statements are true for the methods in the queue in java collections?

  1. Element() method retrieves and removes the head of the queue and returns null if the queue is empty.

  2. Element() method retrieves but doesn’t remove the head of the queue and returns null if the queue is empty.

  3. Element() method retrieves and removes the head of the queue and throws exception if the queue is empty.

  4. Element() method retrieves but doesn’t remove the head of the queue and throw exception if the queue is empty.

  5. Element() method removes the head of the queue and throws exception if the queue is empty.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is the correct answer because element() method retrieves, but doesn’t remove the head of the queue and throw exception if the queue is empty. So, this is correct choice.