A developer writes the following code: int x = 5; System.out.println(x++); What is the output?
Trap 1: Compilation error
Code compiles fine.
Trap 2: 6
This would be the result of ++x.
Trap 3: Runtime exception
No exception occurs.
- A
Compilation error
Why wrong: Code compiles fine.
- B
5
x++ returns 5, then x becomes 6.
- C
6
Why wrong: This would be the result of ++x.
- D
Runtime exception
Why wrong: No exception occurs.