Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

SCJP Chapter 7, Question #16

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Eduardo Mendes
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. The book is Kathy's. I thought that was 'default' here :-)
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Eduardo Mendes
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bert,

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

Best wishes,
Eduardo
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please light on this..
 
reply
    Bookmark Topic Watch Topic
  • New Topic