| Author |
A question in K&B book for SCJP 1.5
|
Jon Lee
Ranch Hand
Joined: Mar 04, 2005
Posts: 134
|
|
Self Test of Chapter One: Question No.5 The answer is B, D. Why (A) is wrong? I think add is a valid prefix in Java bean convention.. The following is quoted from K&B's book for SCJP 1.5
JavaBeans methods must be named using camelCase, and depending on the method's purpose, must start with set, get, is, add, or remove.
[ July 15, 2006: Message edited by: Jon Lee ] [ July 15, 2006: Message edited by: Jon Lee ] [ July 15, 2006: Message edited by: Jon Lee ]
|
SCJP 5.0 - 98% (2007)<br />SCWCD 1.4 - 97% (2007)
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
|
The problem is addSize is not normal usage. If it were setSize it would be OK. The add prefix would be used in addListener, for example, where you are adding to a collection of Listeners, or addObserver where you are adding to a collection of Observers in an Observable, so that they get notified of some event occuring.
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Jon Lee
Ranch Hand
Joined: Mar 04, 2005
Posts: 134
|
|
addSize is not normal usage. But I think it confroms to the JavaBean convention. Does JavaBean define a valid name for a listener?? Why size cant be a name of a listener?? Hope there are no such ambiguous questions in the real exam...  [ July 18, 2006: Message edited by: Jon Lee ]
|
 |
Pavel Kubal
Ranch Hand
Joined: Mar 13, 2004
Posts: 356
|
|
I think listener class name should end with word Listener. I didn't have so ambiguous question in the real exam.
|
 |
Bert Bates
author
Sheriff
Joined: Oct 14, 2002
Posts: 8712
|
|
Hey Guys, First off, Jon, the quote you used was in the summary part of the chapter! By definition, the summary can't contain all of the ins and outs - it's a summary If you go back to page 9, you'll see that we talk in more detail about when "add" is an appropriate prefix (when it's about listeners). Although we have indicated in the errata list that we will clarify that add is ONLY valid in the case of listeners, I think if you read page 9 you'll get the gist. Having said that, I think the mock question is reasonable, but of course I'm always interested in feedback! hth, Bert
|
Eliminate fossil fuel subsidies. (If you're not on the edge, you're taking up too much room.)
|
 |
 |
|
|
subject: A question in K&B book for SCJP 1.5
|
|
|