This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Precedence on Short Circuit Operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Precedence on Short Circuit Operators" Watch "Precedence on Short Circuit Operators" New topic
Author

Precedence on Short Circuit Operators

Stan Forest
Greenhorn

Joined: Mar 03, 2003
Posts: 12
This is a question from Dan's Question Banks.
class A {
static boolean a; // initialized false
static boolean b; // initialized false
static boolean c; // initialized false
public static void main (String[] args) {
boolean x = (a = true) || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}
}
The output is true, false, false.
Doesn't the && has a higher precedence than the ||? My wrong thinking is that it should be true, true, true. How does the precedence work?
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Please check out the following discussion which handles the very same topic:
http://www.coderanch.com/t/241024/java-programmer-SCJP/certification/Operator-Precedence-involving
Thanks


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
 
subject: Precedence on Short Circuit Operators
 
Similar Threads
boolean x = (a = true) || (b = true) && (c = true);
Precedence question!!!
Precedence
operator precedence
Dan's Mock Exam Q - Operators and Precedence