Basically this is what happens.
As the operators work on Right-to-left, first the check on (1==2) is happening.The result of the comparison is assigned to a boolean variable. This is compatible and without compile-time error because the result of comparison (remember! == operator and NOT = operator) would always be of type boolean (true or false).
Since the result of (1==2) is false (obviously!

), the same 'false' is assigned to the boolean variable 'a' (here you got to be careful, because you had used = operator).
The result of an assignment will be the value of the expression.
So, the value 'false' is assigned to 'a' and is checked in if loop thus making the 'else' statement eligible for execution. So, you get "banana" instead of "apples" contradicting to your guess!
Just modify the same program and
test:
This will print "apple" with the same logic explained above.
To just prove the result of assignment is the value returned, see the sample code below.
The output of the above program is :
The last line in the output clearly states and proves the value 'true' is being assigned and also checked for the same.
Hope this helps!