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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes