Oracle
1Z0-809 · Question #158
1Z0-809 Question #158: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-809 to reveal the answer and full explanation for question #158. The question stem and answer options stay visible for context.
Question
Given the following class:
public class Rectangle {
private double length;
private double height;
private double area;
public void setLength(double length) {
this.length = length;
}
public void setHeight(double height) {
this.height = height;
}
public void setArea() {
area = length*height;
}
}
Which two changes would encapsulate this class and ensure that the area field is always equal to length * height whenever the Rectangle class is used?
Options
- ACall the setArea method at the beginning of the setLength method.
- BChange the area field to public.
- CCall the setArea method at the end of the setLength method.
- DCall the setArea method at the beginning of the setHeight method.
- EChange the setArea method to private.
- FCall the setArea method at the end of the setHeight method.
Unlock 1Z0-809 to see the answer
You've previewed enough free 1Z0-809 questions. Unlock 1Z0-809 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.