我正试图做下面的程序。为了将其缩短一点,我删除了MyRectangle2D
的最后一部分。 当我尝试编译时,我得到2个错误,我只是无法通过我的方式!无法编译,类未声明Java
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 {
}
你甚至没有读错误信息... – 2014-12-07 07:24:56