• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Precedence on Short Circuit Operators

 
Stan Forest
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic