Assertions

Q1: Which of the following statements is true?

A It is sometimes good practice to throw an AssertionError explicitly.

B Private getter() and setter() methods should not use assertions to verify arguments.

C If an AssertionError is thrown in a try-catch block, the finally block will be bypassed.

D It is proper to handle assertion statement failures using a catch (AssertionException ae) block.

ANS:A - It is sometimes good practice to throw an AssertionError explicitly.

Option A is correct because it is sometimes advisable to thrown an assertion error even if assertions have been disabled. Option B is incorrect because it is considered appropriate to check argument values in private methods using assertions. Option C is incorrect; finally is never bypassed. Option D is incorrect because AssertionErrors should never be handled.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.