File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics 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 "Generics Question" Watch "Generics Question" New topic
Author

Generics Question

Janardan Kelkar
Ranch Hand

Joined: May 05, 2008
Posts: 72

Given a method declared as:

public static <E extends Number> List<? super E> process(List<E> nums)

A programmer wants to use this method like this:

// INSERT DECLARATIONS HERE

output = process(input);


Which pairs of declarations could be placed at // INSERT DECLARATIONS HERE to allow the code to compile? (Choose all that apply.)

a)ArrayList<Integer> input = null;
ArrayList<Integer> output = null;

b)ArrayList<Integer> input = null;
List<Integer> output = null;

c)ArrayList<Integer> input = null;
List<Number> output = null;

d)List<Number> input = null;
ArrayList<Integer> output = null;

e)List<Number> input = null;
List<Number> output = null;

f)List<Integer> input = null;
List<Integer> output = null;

g)None of the above.


this is a question from KS&BB, chapter 7 self test q#16.The answer given is B,E and F...which i think i understand, however i cannot see why C is also not right??please help..thank you!


When the compiler's not happy, ain't nobody happy.
Noam Wolf
Ranch Hand

Joined: Jan 12, 2008
Posts: 35
Hi Janardan,

Check this thread out: http://www.coderanch.com/t/268612/java-programmer-SCJP/certification/SCJP-Chapter

Looks like you have an outdated copy of the book...


because .net guys can also write in java
Janardan Kelkar
Ranch Hand

Joined: May 05, 2008
Posts: 72

ohh...thank you very much....my wrong i guess..
have my exam tomorrow
Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
All the best!!


Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics Question