posted 20 years ago
This is the complete question
Which of the following situations are good uses of assertions? [Check all correct answers]
# Argument checking in public methods.
# To check the precondition of a lock status.
# To check that a location in your code is never reached.
# Whenever you would have written a comment that asserts an invariant.
# To do any work that your application requires for correct operation.
Answers 2, 3 and 4 are correct as they all confirm your assumptions about the behaviour of your program. Answer 1 is incorrect because argument checking is typically part of the published specifications of a method, and these specifications must be obeyed whether or not assertions are enabled or disabled. Answer 5 is also incorrect, because programs must not assume that the boolean expression contained in an assertion will be evaluated. Therefore, if you use an assertion to do any work that your application requires for correct operation, the program will work fine when asserts are enabled, but would fail when they were disabled.
Try your free <a href="http://www.javacertificate.com" target="_blank" rel="nofollow">SCJP 1.4</a> certification centre.<br />Try your free <a href="http://www.j2eecertificate.com" target="_blank" rel="nofollow">SCWCD</a> certification centre.<br />Try your free <a href="http://www.ejbcertificate.com" target="_blank" rel="nofollow">SCBCD</a> certification centre.<br />Try your <a href="http://www.webspherecertificate.com" target="_blank" rel="nofollow">Websphere (Test 285) </a> certification centre.<br />Try your <a href="http://www.j2mecertificate.com" target="_blank" rel="nofollow">SCMAD</a> certification centre. (New)<br /> <br /><a href="http://blogs.javacertificate.com" target="_blank" rel="nofollow">Java/J2EE Certification Blogging</a>