LearnFrenzy
Sign in Take a free test

Data Structures in Java · Data Structures in Java – Find the Error · Question 3

Error: instantiating the Queue interface Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

Main.java
import java.util.Queue;

public class Main {
    public static void main(String[] args) {
        Queue<String> jobs = new Queue<>();
        jobs.offer("print report");
        System.out.println(jobs.poll());
    }
}
  • A offer should be add
  • B Queue is an interface and cannot be instantiated; use new ArrayDeque<>() or new LinkedList<>() Correct
  • C Queue must be imported from java.lang
  • D poll requires an argument
Correct Answer: Option B

javac: "Queue is abstract; cannot be instantiated".

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links