Question:

What will be the output of the following Java code?

public class Test {
 public static void main(String[] args) {
    int x = 5;
    System.out.println(++x * 2);
  }
}

Show Hint

Pre-increment (++x) updates the variable first, then that new value is multiplied.
Updated On: Jul 2, 2026
  • 12
  • 10
  • 8
  • 14
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Start with \( x = 5 \).

Step 2: The operator ++x is a pre-increment. It raises x by 1 before the value is used, so x becomes 6 and the expression uses 6.

Step 3: Now multiply. \( 6 \times 2 = 12 \).

Step 4: println prints 12. Answer is (A).
Was this answer helpful?
0
0