Which three members must have the private access modifier to ensure that this invariant is maintained?

Given: This class needs to protect an invariant on the sum field. Which three members must
have the private access modifier to ensure that this invariant is maintained?

Given: This class needs to protect an invariant on the sum field. Which three members must
have the private access modifier to ensure that this invariant is maintained?

A.
The setY ( ) method

B.
The x field

C.
The y field

D.
The sum field

E.
The ComputerSum ( ) constructor

F.
The setX ( ) method



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Biga

Biga

Make the fields private as setX and setY methods will update the sum. The problem here is that the fields can be changed directly and any change made not through the setter method may result in an inconsistent state. Making the setters private does not actually make sense.