我正在尝试执行以下程序。我删除了最后一部分MyRectangle2D
以缩短一点。当我尝试编译时,我得到 2 个错误,我就是无法通过!
TestExample.java:17: class GeometricObject2 is public, should be declared in a file named GeometricObject2.java
public abstract class GeometricObject2 {
TestExample.java:11: cannot find symbol
symbol : constructor MyRectangle2D(double,double,double,double)
location: class MyRectangle2D
GeometricObject2 rectangle1 = new MyRectangle2D(1.0, 2.0, 3.0, 4.0);
2 errors
非常感谢您的帮助!
import java.util.*;
public class TestExample
{
public static void main(String[] args)
{
GeometricObject2 rectangle1 = new MyRectangle2D(1.0, 2.0, 3.0, 4.0);
System.out.println(rectangle1.getArea());
}
}
public abstract class GeometricObject2 {
private String color = "white";
private boolean filled;
protected GeometricObject2() {
}
protected GeometricObject2(String color, boolean filled) {
this.color = color;
this.filled = filled;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isFilled() {
return filled;
}
public void setFilled(boolean filled) {
this.filled = filled;
}
public abstract double getArea();
public abstract double getPerimeter();
}
class MyRectangle2D extends GeometricObject2 {
}