Question 9 Which statements are true? a. Assertions should not be used to validate arguments passed to public methods. b. Assertions should not be used to validate arguments passed to nonpublic methods. c. Assertions should not be used within the default case of a switch statement. d. Assertions should not be used to perform processing that is required for the normal operation of the application.
answer is a and d.. why not a,b,d ? can an assertion may used to validate the parameters of a nonpublic method?
Yes, assertions can be used to validate arguments to non-public methods. Choice 'b' says that you should not do this; therefore, it is *not* true. Since you only select the statements that *are* true, choice 'b' is not a right answer.
Assertions should not be used to validate arguments passed to public methods True Because the method gurantess that it will always enforce the argument check. It must check the arguments whether or not assertions are enabled. Argument checking is typically part of the published specifications of a method. Another problem with using assertions fro argument checking is that erroneous arguments should result in an appropriate runtime exception. An assert failure will not throw an appropriate exception. Assertions should not be used to validate the arguments passed to non public methods false Becuase you know the arguments are true no matter what a client does with teh class But you can test the post conditions with assertions in both public and nonpublic methods. post condition: what must be true after a method completes successfully
Assertions should not be used with in the default case of a switch statement True: or False: ??? Ans according to Dan is Yes, but Dan says: For example, a programmer may believe that the default case of a switch statement will never be reached. An assertion can be placed in the default case to verify the behavior of the switch statement.
Assertions should not be used to perform processing that is required for the normal operation of the application True:assertions can be disabled.