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.
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:
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
...
Log in to ExamTopics
Sign in:
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.
MPignaProTech
2 months, 4 weeks ago7df49fb
9 months, 4 weeks agoakbiyik
2 years, 1 month agoiSnover
2 years, 3 months ago