Question: We have a subclass Circle() in our project. It is instantiated as an object, myCircle(). In myCircle, we have a get and set method to
We have a subclass Circle() in our project. It is instantiated as an object, myCircle(). In myCircle, we have a get and set method to determine the area as such:
//Set the area private void setArea(double r){ area = r * r * Math.PI; } //Return the area private double getArea(){ return area; } In the main class, we are calling the set and get methods as such:
//Create a Circle object Circle myCircle = new Circle(); System.out.print("Enter a radius: "); radius = sc.nextDouble(); myCircle.setArea(radius); System.out.printf("The area of this circle is: %.2f ",myCircle.getArea()); What is wrong with this code (if anything)? Will it work? If not, how could it be fixed?
***Note: Assume the scanner object has been created.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
