Oracle 1Z0-808 Exam question no. 60

Q.– Given this 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? 

A) Change the setArea method to private. 

B) Call the setArea method at the beginning of the setLength method. 

C) Call the setArea method at the end of the setHeight method. 

D) Call the setArea method at the beginning of the setHeight method. 

E) Change the area field to public. 

F) Call the setArea method at the end of the setLength method.


⧪ please give your answer in a comment section.

Post a Comment

5 Comments