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