aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K & B Generics Quiz 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 "K & B Generics Quiz question." Watch "K & B Generics Quiz question." New topic
Author

K & B Generics Quiz question.

taichi chen
Greenhorn

Joined: Apr 20, 2006
Posts: 5
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.)

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.

According to the book, B, E, and F are correct.

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 can understand Why A and D are wrong but I am confused on why C is incorrect. can anyone please explain why C is wrong? thanks!
Vishal Chawla
Greenhorn

Joined: Apr 06, 2006
Posts: 28
question is incorrect... refer K &B errata
taichi chen
Greenhorn

Joined: Apr 20, 2006
Posts: 5
Thanks, Vishal... I got it.
taichi chen
Greenhorn

Joined: Apr 20, 2006
Posts: 5
The question should really be:
public static <E extends Number> List<E> process(List<E> nums)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K & B Generics Quiz question.