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

Given:
public class ComputeSum {
public int x;
public int y;
public int sum;
public ComputeSum (int nx, int ny) {
x = nx; y =ny;
updateSum();
}
public void setX(int nx) { x = nx; updateSum();}
public void setY(int ny) { x = ny; updateSum();}
void updateSum() { sum = x + y;}
}
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 x field
B. The y field
C. The sum field
D. The ComputerSum ( ) constructor
E. The setX ( ) method
F. The setY ( ) method

Download Printable PDF. VALID exam to help you PASS.

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.