-2

I'm writing a simple Java program for school. I can't seem to understand why I am getting Error: Cannot Find Symbol .

Here's the whole code with the error at the bottom.

code + error
(Click image to enlarge)

karel
  • 5,489
  • 46
  • 45
  • 50
  • 1
    `RAD` is a parameter that is passed to a method and then that value is stored in the field `radius` - You should use `radius` in your getter method – Scary Wombat Mar 04 '19 at 00:51
  • 3
    Also, please do not post code as images, show the relevant code as text in your question – Scary Wombat Mar 04 '19 at 00:52

3 Answers3

1

You need to understand the concept of scope. Just because you've defined a variable (e.g. RAD) one place in your program, doesn't mean it's available in other places (like "getRadius()").

For example:

public class Circle extends Shape {

  private double radius;
  ...
  public double getRadius() { return radius; }
  ...

This works because I've defined "radius" as a member variable. "radius" is visible anywhere in this class object - and not available at all outside of it.

Which is one example of scope.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
0

In your method getRadius(), you're returning variable RAD that isn't defined in the local method, as a parameter, and it's not a class variable, so RAD is unknown in that method.

Instead of "return RAD" I think you want to "return radius" which is the class variable.

Karlossus
  • 83
  • 7
0

RAD is not declared in the scope of the Method getRadius. Instead of RAD, you should return radius. Another observation in your code, circle() is defined as a method whereas it should be a constructor.

Niran
  • 21
  • 1