-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();
}
Rectangleクラス:
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;
}
}
メインクラス:
Shape rec = new Rectangle();
長方形の高さと幅が等しい場合、Rectangle
クラスの代わりにSquare
クラスが返されます。それは私が欲しいものです。
あなた自身で何か試しましたか? – nullpointer
あなたはどういうことを言っていますか?私はすでに試しました。 –
@tima haha newbieここに –