Question: We have an external (not within the main class) subclass Circle() in our project. It is instantiated as an object, myCircle(). In myCircle, we have
We have an external (not within the main class) 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:
Where it is bold, I added that part of code but I am still missing how the main class accesses the methods. Not sure what I'm missing.
Main class would look like this:
double radius; //Create a Circle object Circle myCircle = new Circle(); System.out.print("Enter a radius: "); radius = in.nextDouble(); myCircle.setArea(radius); System.out.printf(" The area of this circle is: %.2f ",myCircle.getArea()); }
The subclass would look like this:
public class Circle { double area; //Set the area private void setArea(double r){ area = r * r * Math.PI; } //Return the area private double getArea(){ return area; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
