Originally posted by Jack back:
Why the following programme was showing me the output 5
as far as the rules of pre increment, the value is incremented before being assigned and in post increment, the value is assigned to variable before being used.
The post increment happens AFTER evaluating the value of the variable, and BEFORE assignment to the left hand side. The order is this:
a = 1;
EVAL:
Right Side = a = 1; [from a+=]
++a -> 1+a -> 2; [from ++a]
Right Side = 1 + 2; [from + ++a]
a++ -> a -> 2; [from a++]
Right Side = 1 + 2 + 2; [from + a++]
a++ -> a + 1 -> 3; [from a++]
Right Side = 5; [from a+= ++a + a++]
ASSIGN:
a = Right Side = 5;
So why the output was 5 not 6?
Another agony,
Why the following programme compiling successfully?
Because you are allowed to have public static inner classes inside an interface...