Question: Consider the following implementation of a class Square: public class Square { private int sideLength; private int area; // Not a good idea public Square(int

Consider the following implementation of a class Square:

public class Square { private int sideLength; private int area; // Not

public class Square { private int sideLength; private int area; // Not a good idea public Square(int length) { side Length = length; } public int getArea() { } area side Length side Length; return area; } Why is it not a good idea to introduce an instance variable for the area? Rewrite the class so that area is a local variable.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The given implementation of the class Square contains an instance variable for area which is not good practice As a general rule instance variables sh... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!