Home » Java Programming » Assertions

Which of the following statements is true?

Correct Answer: If a switch block has no default, adding an assert default is considered appropriate.

Explanation:

Adding an assertion statement to a switch statement that previously had no default case is considered an excellent use of the assert mechanism.


Option A is incorrect because only Java expressions that return a value can be used. For instance, a method that returns void is illegal.


Option C is incorrect because the expression after the colon must have a value.


Option D is incorrect because assertions throw errors and not exceptions, and assertion errors do cause program termination and should not be handled.


Next Question→

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion