Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions