Online Course Discussion Forum

APCSA chapter 4 question 8

 
 
WangDr. Kevin的头像
Re: APCSA chapter 4 question 8
WangDr. Kevin - 2022年06月25日 Saturday 17:17
 

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".