operators in java: Can anyone explain to me output of the following java code [closed]

The Output:

true,false,false

The secret of the output of your code lies in this line:

x = (a=true) || (b=true) && (c=true);

After evading the first trap – misreading the assignments (=) as comparisons (==) – one might think that each of the variables will be assigned the boolean value of true.

But fact is, that since the first part of the OR (||) – the assignment of true to a ((a=true)) – results in true, the excution of the logical expression (OR) is stopped, it will result in true anyway.
So the second part ((b=true) && (c=true)) is not executed, hence b and c remain false.

Leave a Comment