The following 3 lines of code below compile OK. (Please note that this code is an example of "artificial Java coding", and consequently wouldn't be seen in professionally written code.)
int x, y;
boolean b=true;
x = b ? y=1 : 2; // Compiles OK.
If I now change the code in line #3 above, so that it looks like the following code line below, the compiler generates an error.
// Change the position of the "y assignment", and now the code doesn't compile.
x = b ? 1 : y=2;
Here is the syntax error message:

Can someone please explain this behaviour (to a rookie Java learner)? Thank you.