Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics Question

 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Noam Wolf
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh...thank you very much....my wrong i guess..
have my exam tomorrow
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the best!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic