Here's the code: boolean b1 = false; boolean b2 = false; if (b2 = b1 != b2) { System.out.println("true"); } else { System.out.println("false"); } The output for this code is: false. I'm confused as to why the expression b1 != b2 is evaluated first. What is the logic here? Mansi
In your expression != is a boolean comparison operator and = is a assignment operator. Since the precedence of != is greater than =, the expression b1!=b2 will be evaluated first. ie., b2 = (b1 != b2) b2 = (false != false) b2 = false