"cannot instantiate the type queue" java

Posted on 2011-05-07
Last Modified: 2012-05-11
Hi all

I have a class name ChildG
I a different class Parent, I am doing

private Queue<ChildG> childList;
Queue<ChildG> childList = new Queue<ChildG>();

Then comes the error "cannot instantiate the type queue" java
The literature says that Queue is not a class but an interface..  
How can I correct this?
class constructor
public ChildG(String name, double[] exprValues){
	childName = name;
	this.exprValues = new double[exprValues.length];
	for(int i = 0; i < exprValues.length; i++)
		this.exprValues[i] = exprValues[i];

Open in new window

Question by:ZURINET
    LVL 23

    Accepted Solution

    You need to use any concrete class that implements queue.

    Queue<ChildG> childList = new LinkedList<ChildG>();
    LVL 47

    Assisted Solution

    Queue is interface - you cannot say new Queue()

    You can instantiate clasess but not interfaces.

    Queue can serve as the type, for example:

    Queue<ChildG> childList  = new LinkedList<ChidG>();

    LVL 23

    Expert Comment

    Here LinkedList implements Queue, and hence we can use that.

    To check other classes which implement Queue interface, look under "All Known Implementing Classes:" in,5.0/docs/api/java/util/Queue.html
    LVL 23

    Expert Comment

    You may also want to look into this..

    Author Comment

    Sorry did not realized that LinkedList is a class of its own


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Fix45 challenge 15 66
    array6 challenfge 6 48
    What is JNDI datasource in spring 1 19
    JAVA part two 5 10
    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This video teaches viewers about errors in exception handling.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now