Sim-Ex™ Practice Exams for Java SE 8 Programmer II: Sample Questions


Home     Previous     Up     Next

Q9. What happens when the following code is compiled and run. Select the one correct 

for(int i = 1; i < 3; i++)
for(int j = 3; j >= 1; j--)
assert i!=j : i;

A. The class compiles and runs, but does not print anything.

B. The number 1 gets printed with AssertionError

C. The number 2 gets printed with AssertionError

D. The number 3 gets printed with AssertionError

E. The program generates a compilation error.

Correct Answer: B


correct answer is B. When i and j are both 1, assert condition is false, and AssertionError gets generated.

Home     Previous     Up     Next

Disclaimer: is not affiliated with any certification vendor, and Sim-Ex™ Practice Exams are written independently by and not affiliated or authorized by respective certification providers. Sim-Ex™ is a trade mark of or entity representing® is a trademark of Oracle™.