Java Mysql JavaScript JQuery CSS HTML5 Query Solving Expert
02/01/2021
04. Consider the following two classes (in the same package but defined in different source files):
public class Square {
double side = 0;
double area;
public Square(double length){
this.side = length;
}
public double getSide() {
return side;
}
public void setSide(double side) {
this.side = side;
}
double getArea() {
return area;
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
Square sq = new Square(10.0);
sq.area = sq.getSide()*sq.getSide();
System.out.println(sq.getArea());
}
}
You are assigned the task of refactoring the Square class to make it better in terms of encapsulation. What changes will you make to this class?
Select 2 options
A. Make setSide() method private.
B. Make getArea() method private.
C. Make side and area fields private.
D. Make the side field private and remove the area field.
E. Change getArea method to:
public double getArea(){ return side*side; }
F. Add a setArea() method.
https://www.facebook.com/Codingexperts8
Programming is crucial when it comes to learning how to innovate, create very eco-friendly solutions for global problems and such. In essence, it helps in speeding up the input and output processes in a machine. Additionally, it helps you develop the ability to automate, collect, manage, analyze the data and information correctly.
Enroll today and attend Advanced Java Online Training @ https://www.facebook.com/Codingexperts8
.
Click here to claim your Sponsored Listing.
Category
Website
Address
Gurugram