wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Study Gude Chap 7 Q16 (errata applied) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Study Gude Chap 7 Q16 (errata applied)" Watch "Study Gude Chap 7 Q16 (errata applied)" New topic
Author

Study Gude Chap 7 Q16 (errata applied)

Jacky Zhang
Greenhorn

Joined: Sep 17, 2006
Posts: 18
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 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;

my comments: E replaced by Integer,
which meets the return collection type <Integer>
and the generic declaration <Integer extend Number>.
ArrayList<Integer> should be campatible with List<Integer>
so this is a correct answer.


B. ArrayList<Integer> input = null;
List<Integer> output = null;

my comments: same reasoning as A, this is a correct answer.


C. ArrayList<Integer> input = null;
List<Number> output = null;

my comments: E replaced by Integer,
List<Number> violates the return collection type which should be
List<Integer>

D. List<Number> input = null;
ArrayList<Integer> output = null;

my comments: E replaced by Number,
ArrayList<Integer> violates the return collection type which should
be List<Number>


E. List<Number> input = null;
List<Number> output = null;

my comments: E replaced by Number,
which meets the return collection type List<Number>
and the generic declaration <Number extends Number>.
so this is a correct answer.


F. List<Integer> input = null;
List<Integer> output = null;

my comments: E replaced by Integer,
which meets the return collection type List<Integer>
and the generic declaration <Integer extends number>.
so this is a correct answer.

so my answer would be: ABEF

is it correct?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Study Gude Chap 7 Q16 (errata applied)
 
Similar Threads
K&B Mock question on generics
K&B SJCP 5.0 Study Guide p. 634 - generics and collections question
Collections and Generics Help
Doubt related to use of wild card character ( ? super E)
Study Gude Chap 7 Q16