두 개의 클래스 Circle()과 다른 GeometricObject()가 있습니다. GeometricObject를 원형으로 확장 한 다음 GeometricObject에서 비슷한 기능을 구현해야합니다. 그렇게 할 때 Circle() 클래스에서 추상 메서드를 무시할 수 없다는 오류가 발생하고 Circle()이 추상 메서드가 아닙니다. 나는 또한 테스트/메인 클래스에서 두 가지를 비교해야하지만, 누구든지 내가 어떻게 그 오류를 수정하고 두 가지를 비교할 수있는 아이디어가 있습니까? 미리 감사드립니다.두 객체를 비교, java
package chapter_14;
public class Circle extends GeometricObject{ //here is where i get an error
private double radius;
public Circle() {
}
public Circle(double radius) {
this.radius = radius;
}
/** Return radius */
public double getRadius() {
return radius;
}
/** Set a new radius */
public void setRadius(double radius) {
this.radius = radius;
}
/** Return area */
@Override
public double getArea() {
return radius * radius * Math.PI;
}
/** Return diameter */
public double getDiameter() {
return 2 * radius;
}
/** Return perimeter */
@Override
public double getPerimeter() {
return 2 * radius * Math.PI;
}
/* Print the circle info */
public void printCircle() {
System.out.println("The circle is created " + getDateCreated() +
" and the radius is " + radius);
}
}
GeometricObject 클래스 : 슈퍼 클래스의 메소드가 추상적이기 때문에
package chapter_14;
public abstract class GeometricObject implements Comparable{
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
/** Construct a default geometric object */
protected GeometricObject() {
dateCreated = new java.util.Date();
}
/** Return color */
public String getColor() {
return color;
}
/** Set a new color */
public void setColor(String color) {
this.color = color;
}
/** Return filled. Since filled is boolean,
* so, the get method name is isFilled */
public boolean isFilled() {
return filled;
}
/** Set a new filled */
public void setFilled(boolean filled) {
this.filled = filled;
}
/** Get dateCreated */
public java.util.Date getDateCreated() {
return dateCreated;
}
/** Return a string representation of this object */
@Override
public String toString() {
return "created on " + dateCreated + "\ncolor: " + color +
" and filled: " + filled;
}
/** Abstract method getArea */
public abstract double getArea();
/** Abstract method getPerimeter */
public abstract double getPerimeter();
}
그래서 하위 클래스도 compareTo 메소드를 상속해야합니다. 고쳐서 이제는 테스트 부분을 알아 내야 만합니다. 도움을 많이 주셔서 감사합니다. – Gmenfan83
@ Jason :'GeometricObject'는 그렇게하지 않기 때문에'Comparable'에 선언 된'compareTo' 메쏘드를 구현해야합니다. –