Java OCA OCP Practice Question 250

Question

Which are appropriate uses of assertions?

  • A. Checking pre-conditions in a private method
  • B. Checking post-conditions in a private method
  • C. Checking pre-conditions in a public method
  • D. Checking post-conditions in a public method


A, B, D.

Note

Assertions are appropriate for checking post-conditions in all methods and for checking pre-conditions in most methods.

They are not appropriate for checking pre-conditions in public methods, however, because public methods are often called in environments where assertions are not enabled.




PreviousNext

Related