• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

OCA Java SE 8 study guide chapter 4 question 9

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using OCA Java SE 8 study guide by Jeanne and Scott. In chapter 4 question 9, the answer is A, C, E. I am agree C and E, but didn't understand how A is correct. Table 4.5 says that, the naming convention for boolean return type must be start with "is". So, the method name should be "isCanSwim()", instead of "getCanSwim()".

Please let me know whether there is any mistake in book or my understanding is wrong. Any help will be appreciated.
 
Marshal
Posts: 65105
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I couldn't find any reference to that question elsewhere. Please provide more details of the question for those of us who don't have the book. Yes, methods returning a boolean are usually called isXXX() rather than getXXX(), but it is a bit of an exaggeration to say you must follow that convention. It is only compulsory if you are following the Bean “patter‍n”. I would find isCanSwim() a dreadful mouthful to pronounce.
 
Rachit Trivedi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your quick reply. In here, I am copying the whole question with answer, it is from review questions of the chapter:

Which are methods using JavaBeans naming conventions for accessors and mutators?
(Choose all that apply)
A. public boolean getCanSwim() { return canSwim;}
B. public boolean canSwim() { return numberWings;}
C. public int getNumWings() { return numberWings;}
D. public int numWings() { return numberWings;}
E. public void setCanSwim(boolean b) { canSwim = b;}

This is the answer for the same question:

A,C, E.
Option A is correct because the property is of type boolean and getters must begin with is for booleans. Options B and D are incorrect because they don’t follow the naming convention of beginning with get/is/set. Options C and E follow normal getter and setter conventions.

Following is the link for the posted around 2 months ago. It was for the same question (but in different context).
https://coderanch.com/t/706490/certification/Chapter-Review
 
Ranch Hand
Posts: 272
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rachit Trivedi wrote:I am agree C and E, but didn't understand how A is correct. Table 4.5 says that, the naming convention for boolean return type must be start with "is". So, the method name should be "isCanSwim()", instead of "getCanSwim()".

Please let me know whether there is any mistake in book or my understanding is wrong. Any help will be appreciated.

According to Table 4.5 (2nd row),

Getter methods begin with is or get if the property is a boolean.



I hope that helps.

Charles
 
Campbell Ritchie
Marshal
Posts: 65105
247
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Charles O'Leary wrote:. . . I hope that helps.

Charles

Yes, it does; thank you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!