aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generic Methods question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generic Methods question" Watch "Generic Methods question" New topic
Author

Generic Methods question

matthew meltzer
Greenhorn

Joined: Sep 08, 2012
Posts: 24

Q8: Which collection types, when inserted at (1), will result in a generic method that will compile without errors?

public static <T> T justDoIt(______/* (1) INSERT TYPE HERE */ ____ <T> collection){
return collection.poll();
}

There may be more than one correct answer.

(a) PriorityQueue
(b) LinkedList
(c) Queue
(d) TreeSet
(e) LinkedHashSet



Here is the question. It is part of my homework assignment for chapter 7 in the SCJP study guide. I keep looking over the book but cannot figure it out.... Right now I am leaning towards A and B for the answer....Can anyone help me understand the problem and figure out which answers are correct?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Well, the most reliable way to find out which of those will compile is to ask the compiler. Try them out, see whether you get any errors, and what errors they are.

The error messages you get may well make it clear to you why the wrong answers are wrong. But the obvious question to ask for me is this: which of those types has a poll() method?
Ankit Gareta
Ranch Hand

Joined: Mar 28, 2011
Posts: 67

matthew meltzer wrote:Q8: Which collection types, when inserted at (1), will result in a generic method that will compile without errors?

public static <T> T justDoIt(______/* (1) INSERT TYPE HERE */ ____ <T> collection){
return collection.poll();
}

There may be more than one correct answer.

(a) PriorityQueue
(b) LinkedList
(c) Queue
(d) TreeSet
(e) LinkedHashSet



Here is the question. It is part of my homework assignment for chapter 7 in the SCJP study guide. I keep looking over the book but cannot figure it out.... Right now I am leaning towards A and B for the answer....Can anyone help me understand the problem and figure out which answers are correct?


poll() method resides in Queue interface, and both LinkedList and PriorityQueue implements Queue, so answer is a,b,c.


OCPJP 6 (91%)
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

matthew meltzer wrote:Q8: Which collection types, when inserted at (1), will result in a generic method that will compile without errors?

public static <T> T justDoIt(______/* (1) INSERT TYPE HERE */ ____ <T> collection){
return collection.poll();
}

There may be more than one correct answer.

(a) PriorityQueue
(b) LinkedList
(c) Queue
(d) TreeSet
(e) LinkedHashSet



Here is the question. It is part of my homework assignment for chapter 7 in the SCJP study guide. I keep looking over the book but cannot figure it out.... Right now I am leaning towards A and B for the answer....Can anyone help me understand the problem and figure out which answers are correct?

matthew, this is your home work to find out the correct answers. These type of Question you will see on the certification Exam. The main motive of these questions is to confuse you, but if your concepts are clear only then you can answer, if you are unable to answer its better if you re-re-re-re revise your notes that is what the writers of this book wants.So, its better if you ask doubts instead of a question straight from book.

OCPJP 6 86%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generic Methods question
 
Similar Threads
is it Collection or collection ??
Generic Method problem
collection operation
Ultimate generics Q
Generics warnings... I don't understand?!