112k views
2 votes
Which of the following is true?

a. A precondition must be true when a method is invoked.
b. A postcondition must be true when a method successfully returns to its caller.
c. Both of the above.
d. Neither of the above.

1 Answer

5 votes

Final answer:

The correct option is c. Both of the above, as preconditions must be true before a method is invoked and postconditions must be true after the method successfully returns.

Step-by-step explanation:

The correct answer to the question of which statement is true regarding preconditions and postconditions in a programming context is c. Both of the above. A precondition is something that must be true before a method is invoked to ensure the method functions correctly. On the other hand, a postcondition is something that must be true after the method successfully returns; it's the method's guarantee upon completion. In summary, the precondition sets the requirements for the method to run properly, while the postcondition is the expectation that should be met once the method has executed successfully.

User Chinthaka Dinadasa
by
9.0k points

Related questions