我正試圖做下面的程序。爲了將其縮短一點,我刪除了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