exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 126 discussion

Actual exam question from Oracle's 1z0-808
Question #: 126
Topic #: 1
[All 1z0-808 Questions]

Given this class:

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?
(Choose two.)

  • A. Call the setArea method at the end of the setHeight method.
  • B. Call the setArea method at the beginning of the setHeight method.
  • C. Call the setArea method at the end of the setLength method.
  • D. Call the setArea method at the beginning of the setLength method.
  • E. Change the setArea method to private.
  • F. Change the area field to public.
Show Suggested Answer Hide Answer
Suggested Answer: AC 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
MPignaProTech
2 months, 4 weeks ago
Selected Answer: AC
good answer is A/C
upvoted 1 times
...
7df49fb
9 months, 4 weeks ago
The goal here is to ensure that the area field is always updated correctly whenever length or height is modified. Encapsulation involves restricting direct access to fields and ensuring that they are modified through controlled methods. Given the provided options, here are the changes that would encapsulate the class and ensure that the area field is always equal to length * height: Call the setArea method at the end of the setHeight method. This ensures that whenever the height is set, the area is recalculated. Call the setArea method at the end of the setLength method. Similarly, this ensures that whenever the length is set, the area is recalculated. So, the correct choices are A and C:
upvoted 2 times
...
akbiyik
2 years, 1 month ago
Selected Answer: AC
The answer is AC public class Rectangle { private double length; private double height; private double area; public void setLength(double length) { this.length = length; setArea(); } public void setHeight(double height) { this.height = height; setArea(); } public void setArea() { this.area = length * height; } public static void main(String[] args) { Rectangle a = new Rectangle(); a.setHeight(2); a.setLength(3); a.setArea(); System.out.println(a.area); } }
upvoted 1 times
...
iSnover
2 years, 3 months ago
Selected Answer: AC
The answer is AC, to do what is asked by the question, you must put the method at the end of the set method of each one.
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago