Page 1 of 1

About Question enthuware.ocajp.i.v8.2.1408 :

Posted: Sun Feb 13, 2022 1:01 pm
by Elvira Sharipova
Hello! The explanation states that "Comparison operators have lower precedence than mathematical operators."
But what if we have something like this:
int x1 = 50, x2 = 75;
boolean b = x1 >=x2;
Is it equal to boolean (b = x1) >=x2; or to boolean b = (x1 >=x2);?
What will be evaluated first: the comparison or assigning x1 value to b?

Re: About Question enthuware.ocajp.i.v8.2.1408 :

Posted: Mon Feb 14, 2022 12:06 am
by admin
= is not a mathematical operator, so, why do you think it can be boolean (b = x1) >=x2; ?

= is an assignment operator and has the lowest precedence out of all (except lambda).

You may want to go through this article to understand the basics of expression evaluation:
https://enthuware.com/oca-ocp-java-cert ... evaluation