Multiple choice technology programming languages

class C{ static int f1(int i) { System.out.print(i + ","); return 0; } public static void main (String[] args) { int i = 0; i = i++ + f1(i); System.out.print(i); } } What is the result of attempting to compile and run the program?

  1. Prints: 0,0

  2. Prints: 1,0

  3. Prints: 0,1

  4. Compile-time error

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

Java evaluates expressions left-to-right. i++ returns 0 then increments i to 1. f1(i) is called with i=1, prints '1,' and returns 0. So i = 0 + 0 = 0. The post-increment result (0) is assigned to i, overwriting the increment. Output: 1,0

AI explanation

Java evaluates the left operand of + before the right one. i++ (post-increment) yields the original value of i (0) as the expression's value, then increments i to 1. Then f1(i) is called with the now-updated i (1), so it prints "1," and returns 0. The sum 0 + 0 = 0 is assigned back to i, so the final System.out.print(i) prints 0 — giving the combined output "1,0".