-1
도형의 영역과 둘레를 계산하는 할당이 있습니다. 하위 클래스의 하위 클래스를 반환하십시오.
슈퍼 클래스 :public abstract class Shape implements Serializable {
private static final long serialVersionUID = -1231855623100981927L;
public abstract boolean draw();
public abstract String area();
public abstract String perimeter();
public abstract String characteristic();
}
사각형 클래스 :
public class Rectangle extends Shape {
private double x;
private double y;
public Rectangle() {}
public Rectangle(double x, double y) {
this.x = x;
this.y = y;
}
}
광장 클래스 :
public class Square extends Rectangle {
private double x;
public Square() {}
public Square(double side) {
super(side, side);
this.x = side;
}
public Square square(double side){
this.x = side;
return this;
}
}
Main 클래스 :
Shape rec = new Rectangle();
원하는 것은 사각형의 높이와 너비가 동일 할 때 Rectangle
클래스 대신 Square
클래스를 반환합니다. 그게 내가 원하는 전부 야.
혼자서 시험해 보셨습니까? – nullpointer
그게 무슨 소리 죠? 나는 벌써 노력했다. –
@tima haha newbie 여기에 –