Java™ Certification: SCJP™ 6- Sun Certified Java Programmer Exam

Assertion

Home     Previous     Up     Next

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

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

Explanation:

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

Home     Previous     Up     Next


Disclaimer: All Simulation Exams practice tests, study guides and/or material are neither sponsored by, nor endorsed by, nor affiliated with Oracle® or any other company. All trademarks are trademarks of their respective owners and duly acknowledged. OCA™, OCPJP™, SCJP™ are registered trade marks of Oracle®. . The practice tests material is a copyright of SimulationExams.com and the same is not approved or endorsed by respective certifying bodies. Thank-you for your interest in Simulation Exams. Please see read me file before you download, install, and/or use any software from SimulationExams.com For any information or questions regarding this Website, please e-mail webmaster at simulationexams.com