I copied this code from the textbook, so the code should have no mistake? I typed the contructor file(I think thats what its called) and the actual codes. So the code looks like this:
public class TestCircle {
public static void main(String[] args) {
Circle spot = new Circle();
spot.setRadius(5);
System.out.println("Circle radius:" + spot.getRadius());
System.out.println("Circle area: " + spot.area());
}
}
And I saved it as TestCircle.java
the constuctor file:
/**
* Circle class.
*/
public class Circle {
private static final double PI = 3.14;
private double radius;
/**
* constructor
* pre: none
* post: A circle object created. Radius initialized to 1.
*/
public Circle() {
radius = 1; //default radius
}
/**
* Changes the radius of the circle.
* pre: none
* post: radius has been changed.
*/
public void setRadius(double newRadius) {
radius = newRadius;
}
/**
* Calculates the area of the circle.
* pre: none
* post: The area of the circle has been returned.
*/
public double area() {
double circleArea;
circleArea = PI * radius * radius;
return(circleArea);
}
/**
* Returns the radius of the circle.
* pre: none
* post: The radius of the circle has been returned
*/
public double getRadius() {
return(radius);
}
}
Saved it as Circle.java
When I compile it, it's fine.. no errors but when I go to see the ouput it gives me this:
> java Circle
Static Error: No static method in Circle with name 'main' accepts arguments (String[])
What does that mean, how do I fix it?
I think this happens to most of the programs I to run.