Multiple choice technology programming languages

what is the value of x and y after running this code? class a { public static void main(String args[]) { int x=1; int y=x++; } }

  1. x=1 and y=1

  2. x=2 and y=2

  3. x=1 and y=2

  4. x=2 and y=1

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is identical to question 130241. The post-increment operator x++ first returns the current value (1) to y, then increments x to 2. Result: x=2, y=1. The post-increment operator's behavior is that it returns the original value before performing the increment.