This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B "SCJP 5.0" Chapter 7 -Q16 - Error?" Watch "K&B "SCJP 5.0" Chapter 7 -Q16 - Error?" New topic
Author

K&B "SCJP 5.0" Chapter 7 -Q16 - Error?

Tommaso Nuccio
Ranch Hand

Joined: Dec 11, 2006
Posts: 66
Hi there,

I just took the selftest and while reviweing the answers, I got stuck on the last question.

Q16:
Given a method declared as
-> public static <E extends Number> List<E> process(List<E> nums)
A programmer wants to use this method like this:
//INSERT DECLARATIONS HERE
output = process(input)

Which pairs could be inserted at //INSERT DECLARATIONS HERE ?

A.
B.
ArrayList<Integer> input = null;
List<Integer> output = null;
C.
ArrayList<Integer> input = null;
List<Number> output = null;
D.
E.
List<Number> input = null;
List<Number> output = null;
F.
List<Integer> input = null;
List<Integer> output = null;
G.

The answers should be B,E,F, but not C.

The explanation to C is:
"C is wrong because the return type evaluates to List<Integer>, and that can't be assigned to a variable of type List<Number>."
I absolutely understand this, but then, why is F correct?

Any help appreciated.

Many Thanks in advance.


Ciao,<br /> Tommaso<br /> <br />~*~*~*~<br />There are 10 types of people, those who understand binary and those who don't.
Tommaso Nuccio
Ranch Hand

Joined: Dec 11, 2006
Posts: 66
Oha!

I think I understand it now.
It's because in C the input is ArrayList<Integer>!!

Darn..

Thanks anyway.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B "SCJP 5.0" Chapter 7 -Q16 - Error?