Menu
Topics Index
...
`

Collections1965


If you need explanation Read this topic

If you need Answer Take test on this topic

Collections1965
How should we declare a collection so that program will compile without error?
import java.util.*;

class MyClass {
}
public class MyGraphics {
    
    /* INSERT CODE HERE */

    public synchronized void addCollection(MyClass var1) {
        coll.add(var1);
    }
    public synchronized MyClass getCollection() {
        return coll.poll();
    }
}

A. Queue coll = new LinkedList();
B. LinkedList coll = new LinkedList();
C. Queue coll = new ProrityQueue();
D. Queue coll = new Queue();
E. None of the above
Topic: Java Collection Framework - Collections In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is C.. poll method exists in priority queue. so we need to create object for priority queue..

Posted by Nanda Kishore    2013-11-27 09:11:30


e

Posted by Aruna Dantu    2013-11-27 09:37:31


Answer is E : PriorityQueue is a raw type. References to generic type PriorityQueue<E> should be parameterized...Thus we should write..!! Queue<MyClass> coll = new PriorityQueue<Myclass>();

Posted by Sana Ferdouse    2013-11-27 10:01:14


Congratulations Sana Ferdouse. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2013-11-28 03:18:07


© meritcampus 2019

All Rights Reserved.

Open In App