Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CertPal question (JavaBean naming standards)

 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I got this Q/A from CertPal mock exam.

Q) If a java bean has a boolean variable named tankFull, how would you provide getters and setters for it?
Options(choose 1):

1) public boolean isTankFull(){return tankFull;}
public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}

2) public boolean getTankFull(){return tankFull;}
public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}

3) public boolean getTankFull(boolean tankFull){return tankFull;}
public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}

4) public boolean gettankFull(){return tankFull;}
public void settankFull(boolean tabkFull){this.tankFull = tabkFull;}

5) None of the above


The correct answer is listed as option 1. But, shouldn't the correct answer be option 2?

Thanks,
Nidhi
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, 1 is absolutely correct.
because isTankFull is more meaning full than setTankFull!
we always use "is" with boolean variables into java bean classes.
 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Minhaj kaimkhani wrote:No, 1 is absolutely correct.
because isTankFull is more meaning full than setTankFull!
we always use "is" with boolean variables into java bean classes.


Wow... I didn't know that. Thought it was setX() & getX() for all getters/setters and isX() - an additional(allowed) method. Thanks so much!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic