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 SCJP Chapter 7, Question #16 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "SCJP Chapter 7, Question #16" Watch "SCJP Chapter 7, Question #16" New topic
Author

SCJP Chapter 7, Question #16

Eduardo Mendes
Ranch Hand

Joined: Apr 30, 2008
Posts: 30
Hi everyone,

can anyone help with this. I am using SCJP5 Study Guide, and have a problem on the question 16 of the Chapter 7 self test. There is no way my compiler (Eclipse, compliance 5.0) gives me the results as told in the book answer. Actually, the compiler says all three answers (B, E and F) are INCORRECT, i.e. it does not compile if I use any of those options. Did anyone face the same issue, or am I missing something here?

Many thanks for your help!
Eduardo
Vishal Matere
Ranch Hand

Joined: Jan 22, 2008
Posts: 81
Originally posted by Eduardo Mendes:
I am using SCJP5 Study Guide, and have a problem on the question 16 of the Chapter 7 self test.
Eduardo


Can you post the actual question here. Many people may not be using same book or they may have already done SCJP hence done refer any book anymore.
It will be useful if you post actual question, so that even if somebody answer from Book atleast we come to know what question was...


SCJP <br />SCWCD <br />SCBCD <br />SCEA-1
Eduardo Mendes
Ranch Hand

Joined: Apr 30, 2008
Posts: 30
Sure, pardon me.

Given a method declared as
public static <E extends Number> List<? super E> process(List<E> nums)

// INSERT CODE HERE
output = process(input);

Which pairs of declarations could be placed at // INSERT CODE HERE

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

Before I tried to code this, I thought 'C' would be the right answer. But my compiler tells me it's G...

I wonder if I should just give up on this exame... :-(

Thanks again for the help!
Eduardo Mendes
Ranch Hand

Joined: Apr 30, 2008
Posts: 30
P.S. The book is Kathy's. I thought that was 'default' here :-)
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hi Eduardo,

Somehow you've gotten an old, old copy of the book! This was an errata (you can find a link to a list of errata at the top of this forum), from a long time ago.

Instead of List<? super E>

it should read:

List<E>

hth,

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Eduardo Mendes
Ranch Hand

Joined: Apr 30, 2008
Posts: 30
Hi Bert,

thank you so much. Wasn't expecting an answer from one of the authors himself! :-)

Best wishes,
Eduardo
kishor kalapa
Greenhorn

Joined: Jun 05, 2008
Posts: 24
HI all,
k&b pg 621
-----------------------------------------------------------------------------
Given a method declared as
public static <E extends Number> List<E> process(List<E> nums)

// INSERT CODE HERE
output = process(input);

Which pairs of declarations could be placed at // INSERT CODE HERE

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
---------------------------------------------------------------------------------
As per K&B book ans:-B,E,F
but i think 'A' also correct because return type follows polymorphism so if
return type is ArrayList also it can handle by List,Is it correct?
kishor kalapa
Greenhorn

Joined: Jun 05, 2008
Posts: 24
please light on this..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SCJP Chapter 7, Question #16