Java OCA OCP Practice Question 3106

Question

Consider the following program:

import java.util.*;

public class Main {
        public static void main(String []args) {
               Deque<Integer> deque = new ArrayDeque<>();
               deque.addAll(Arrays.asList(1, 2, 3, 4, 5));
               System.out.println("The removed element is: " + deque.remove()); // ERROR?
        }
}

Which one of the following correctly describes the behavior of this program?

  • a) When executed, this program prints the following: "The removed element is: 5".
  • b) When executed, this program prints the following: "The removed element is: 1".
  • c) When compiled, the program results in a compiler error of "remove() returns void" for the line marked with the comment ERROR.
  • d) When executed, this program throws InvalidOperationException.


b)

Note

The remove() method is equivalent to the removeFirst() method, which removes the first element (head of the queue) of the Deque object.




PreviousNext

Related