Online Course Discussion Forum

APCSA chapter 4 question 8

Picture of Dr. Kevin Wang
Re: APCSA chapter 4 question 8
by Dr. Kevin Wang - Saturday, June 25, 2022, 5:17 PM

The main() method is static, not part of any instance, and the getArea() method is not static, so it has to be invoked from an instance, like this: circle.getArea(radius). 

There are a few other problems.  The getRadius() method should return "radius", not "r".  The getArea() method, as written, calculates the area of any general circle, not the current instance, so it may be better to use "radius" field to calculate, instead of taking an input argument "r".