Question 4
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
import java.util.ArrayDeque;
import java.util.Queue;
public class Main {
public static void main(String[] args) {
Queue<Integer> q = new ArrayDeque<>();
q.push(10);
q.push(20);
System.out.println(q.peek());
}
}
- A ArrayDeque has no push method
- B push is declared in Deque, not Queue; declare the variable as Deque<Integer> or use offer Correct
- C peek is not allowed on a Queue
- D Integer cannot be stored in a Queue
Correct Answer: Option B
The compiler only allows the methods of the declared type. javac: "cannot find symbol – method push(int)".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!