Java OCA OCP Practice Question 2125

Question

Choose the correct option based on this 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?
    }/*w  w w. java2s .c  om*/
}
  • 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