• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Doubt in K&B SCJP 6: Ch 7, Q 5

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This class is to be updated to make use of appropriate generic types, with no changes in behavior
(for better or worse). Which of these steps could be performed? (Choose three.)
Correct answers are
B. Replace line 13 with
private Map<String, Integer> accountTotals = new HashMap<String, Integer>();
E. Replace lines 17–20 with
Integer total = accountTotals.get(accountName);
if (total == null) total = 0;
return total;
G. Replace line 24 with
accountTotals.put(accountName, amount);

My doubt is, why should option G be in the list of answers?
Though it does not harm replacing line 24, but it is unnecessary as far as the question is concerned(just making use of generic types)
Can anyone please correct me, if I am wrong?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Divyeshh Patel wrote:Though it does not harm replacing line 24, but it is unnecessary as far as the question is concerned(just making use of generic types)


if you were not apply generic, then there is a possibility to put any Object into Map right? example : aMap.put(key, new Object()); where in generic only you can put Integer or its subclass

hth
 
Divyeshh Patel
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Seetharaman Venkatasamy wrote:

Divyeshh Patel wrote:Though it does not harm replacing line 24, but it is unnecessary as far as the question is concerned(just making use of generic types)


if you were not apply generic, then there is a possibility to put any Object into Map right? example : aMap.put(key, new Object()); where in generic only you can put Integer or its subclass

hth


Please read the post carefully, I am sorry to say but I think your thoughts are totally irrelevant to my doubt. It is not about whether we can put an Object into a Map or not, it is only about replacing the existing line.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, your question sounds valid one !
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hopefully by seeing such question you will realize that exam is made to clear your concepts..

both of them is correct you can use any..

but here question is saying "with no changes in behavior"

and you have to select options as per the question
you can easily search 2 points for any questions...
but here they have made it tough for you for third question..

even i was confused why this is the option..when i am preparing for the exam.


you can use any both are valid.........

Happy learning......
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic