[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

"cannot instantiate the type queue" java

Posted on 2011-05-07
5
Medium Priority
?
2,225 Views
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

0
Comment
Question by:ZURINET
  • 3
5 Comments
 
LVL 23

Accepted Solution

by:
cmalakar earned 1200 total points
ID: 35711268
You need to use any concrete class that implements queue.

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

Assisted Solution

by:for_yan
for_yan earned 800 total points
ID: 35711272
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>();

0
 
LVL 23

Expert Comment

by:cmalakar
ID: 35711275
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

http://download.oracle.com/javase/1,5.0/docs/api/java/util/Queue.html
0
 
LVL 23

Expert Comment

by:cmalakar
ID: 35711284
You may also want to look into this..

http://mindprod.com/jgloss/interface.html#INSTANTIATING
0
 

Author Comment

by:ZURINET
ID: 35711292
Sorry did not realized that LinkedList is a class of its own

Regards
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 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