What will be the result of compilation and execution of the following code:

public class Main {
    public static void main (String []args) {
        int i = 0;
        i += i++;
        System.out.println(i);
    }	
}
Explanation
JLS $15.7.1. Compound assignment operator is equivalent to i = i + i++ and is executed accordingly.
i will be incremented after evaluating the expression but before the assignment.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback