• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

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: 9008
20
  • 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..
 
Don't play dumb with me! But you can try this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic