STEP 1: i++ is evaluated first because of associativity, and because postfix operations has higher precedence. The result of the expression is still 0 because under JLS(15.14.1)
The value of the postfix increment expression is the value of the variable before the new value is stored.
STEP 2: m(i) is evaluated next. However, the value of i at this point is the incremented i. m(i) will print "1" but returns "0". STEP 3. Finally, addition is performed, which would look something like this: i = <result in Step 1> + <result in Step 2> = 0 + 0 i = 0
If you where to interchange their positions like this:
the result would be different.
Joined: May 16, 2003
Thanks, I think I got a handle on it. I now evaluate the expressions left to right and it helps to write down the intermediate expression as you did.