I get \"The method main cannot be declared static; static methods can only be de
ID: 3553070 • Letter: I
Question
I get "The method main cannot be declared static; static methods can only be declared in a static or top level type" for the following program and I cannot see what the problem is.
import java.util.Scanner;
public class Rectangle {
public class MyRectangle {
private double length;
private double width;
public MyRectangle() {
length = 2.5;
width = 3.2;
}
double getArea() {
double area;
return area = length * width;
}
public double perimeter() {
return length + width + length + width;
}
public double getLength() {
return length;
}
public double setLength(double d) {
return length;
}
public double getWidth() {
return width;
}
public double setWidth() {
return length;
}
}
public class TestRectangle {
public static void main(String[]args) {
MyRectangle rectangleOne = new MyRectangle();
double area = rectangleOne.getArea();
System.out.println("Area is: " + area);
rectangleOne.setLength(4.5);
double width = rectangleOne.getWidth();
System.out.println("Width is: " + width);
MyRectangle rectangleTwo = new MyRectangle();
double areaTwo = rectangleOne.getArea();
System.out.println("Area is: " + areaTwo);
double perimeter = rectangleOne.perimeter();
System.out.println("Perimeter is: " + perimeter);
}
}
}
Explanation / Answer
you are putting closing brackeet wrong.public class Rectangle wasn't closed before public class TestRectangle
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.