class Test
{
static boolean a;
static boolean b;
static boolean c;
public static void main (String[] args)
{
boolean bool = (a = true) || (b = true) && (c = true);
System.out.print(a + ", " + b + ", " + c);//it will print "true, false, false"
}
}
I did not understand. Based on http://docs.oracle.com/javase/tutorial/ ... ators.html (operator precendence) && comes before || so should evaluate first right side "(b = true) && (c = true)" and print "true, true, true" or perhaps "false true true".
Java language specification doesn't mention anywhere that && has more precedence than ||. In absence of any such precedence, evaluation order is left to right as explained here: http://docs.oracle.com/javase/specs/jls ... l#jls-15.7
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
I read in the page : "The closer to the top of the table an operator appears, the higher its precedence." and "Operators on the same line have equal precedence". Then i see that && are closer to the top then || , and && and || not are on the same line.