nerdexam
Exams1Z0-803Questions#223
Oracle

1Z0-803 · Question #223

1Z0-803 Question #223: Real Exam Question with Answer & Explanation

The correct answer is A: The x field. See the full explanation below for the reasoning.

Question

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?

Options

  • AThe x field
  • BThe y field
  • CThe sum field
  • DThe ComputerSum ( ) constructor
  • EThe setX ( ) method
  • FThe setY ( ) method

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice