Hi Sneha!
You could have posted this question into another new
thread, as this one goes under the subjectline "Regarding SCJP". May be you can explore more of Java Ranch policies here.
http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch Coming back to your query, it is "pre-increment expression" as the name suggests... it says "use the value of the expression before the increment happens". So the expression
i++
says 'use the value of i
before it is incremented'. That way,
i = i++;
gets evaluated to
"i = 0";
Remember this expression "i=0" has not been executed yet. It would remain as it is and get evaluated after the increment has happened.
Now the increment happens, i from 0 becomes 1(somewhere in memory);
and after that the expression is evaluated, i.e.
i=0;
so i becomes 0 again.
Try excuting the following code,
Check out this link as well,
http://radio.javaranch.com/corey/2004/04/20/1082478396000.html