What will happen when you attempt to compile and run the following code?
1.public class Inc
2.{
3. public static void main(
String argv[])
4. {
5. Inc inc = new Inc();
6. int i =0;
7. inc.fermin(i);
8. i = i++;
9. System.out.println(i);
10. }
11. void fermin(int i){
12 i++;
13. }
14.}
1) Compile time error
2) Output of 2
3) Output of 1
4) Output of 0
The result is (4).
In line 8,the value of 'i'(before increment ie. '0')is assigned .After the assignment ,a post increment operation takes place(on the "same variable"),which increase the value of 'i'.
Why is the new value of 'i' not reflected when printed ?
[This message has been edited by Savio Mascarenhas (edited December 11, 2000).]