aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help me understand 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 "Help me understand" Watch "Help me understand" New topic
Author

Help me understand

Sree Potluri
Ranch Hand

Joined: Aug 12, 2009
Posts: 62

public class Test {
//insert here
{
List<T> output = new LinkedList<T>();
for (T t:input)
output.add(0,t);
return output;
}
}

which can be inserted //insert here to compile and run without error
A. public static <T> List <T> backwards(List<T> input)
B. public static <T> List <T> backwards(List<? extends T> input)
C. public static <T> List <T> backwards(List<? super T> input)
D. public static <T> List <? extends T> backwards(List<T> input)
E. public static <T> List <? super T> backwards(List<T> input)
F. public static <? extends T> List <T> backwards(List<T> input)
G. public static <? super T> List <T> backwards(List<T> input)

Correct answer A, B, D, E

Help me understand this
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
hey what didnt you understand? you must have eliminated something by yourself....just asking....


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
why do you think C is wrong whereas B is right?
Sree Potluri
Ranch Hand

Joined: Aug 12, 2009
Posts: 62
How do I determine where to use "extends" and where to use "super" in this kind of scenario. Do these type of questions appear in exam?
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
yup i faced a similar kind of question in the exam
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
suppose in either B or C you pass in a List<Animal>.....so that means T is animal...in the ? extends Animal option what you get outside is an animal, that is, the return type is animal...so in the B option T is the return type..which is right...but in ? super Animal you can pass in anything that is the superclass of super...which means you only get an object out of it...so the return type cant be T or animal..this is why C is wrong..understood anything?
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
http://www.coderanch.com/t/474163/Programmer-Certification-SCJP/certification/generics-extends
Sree Potluri
Ranch Hand

Joined: Aug 12, 2009
Posts: 62
Thanks Raju, but can you give me another example.
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
i think there are enough examples in the above link
Sree Potluri
Ranch Hand

Joined: Aug 12, 2009
Posts: 62
Thanks for the help Raju
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3100
    
  40

Have a look at this topic too.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

Sree please Quote Your Sources when you post a question...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help me understand