Question 1
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
import java.util.ArrayDeque;
import java.util.Deque;
public class Main {
public static void main(String[] args) {
Deque<int> stack = new ArrayDeque<>();
stack.push(1);
System.out.println(stack.pop());
}
}
- A ArrayDeque cannot be used as a stack
- B Type arguments must be reference types; use Deque<Integer> (autoboxing handles push(1)) Correct
- C push needs an index
- D pop must be assigned to a variable
Correct Answer: Option B
javac: "unexpected type – required: reference, found: 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!