Given the code fragment:
What is the result if the integer aVar is 9?
A. Compilation fails.
B. 10 Hello Universe!
C. 10 Hello World!
D. 9 Hello World!
Given the code fragment:
What is the result if the integer aVar is 9?
A. Compilation fails.
B. 10 Hello Universe!
C. 10 Hello World!
D. 9 Hello World!
# javac Test45.java
# java Test45
10 Hello World!
Answer C:
At the if statement, aVar++ will be executed only after the full line is executed. Therefore, when aVar is 9, it will pass the the condition and gets into the println statement. However, at this point, the aVar++ will be executed, making aVar 10. So it prints 10 Hello World!
Correct answer is C
10 Hello World!