File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes boolean return question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "boolean return question" Watch "boolean return question" New topic

boolean return question

Quang Pham
Ranch Hand

Joined: Nov 29, 2005
Posts: 47
Can some one explain the following code:

boolean a = false;
boolean b = false;
boolean c = false;

public boolean isOptionValid(){
return a||b||c;

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11952

the || operator means "shortcut logical OR". do you know your boolean logic rules?

a OR b OR c

since in this case all three are false, the result is false, so false is returned.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: boolean return question
It's not a secret anymore!