こんにちは、スーパークラスとそのコンストラクタースーパーを拡張するクラスからオブジェクトをインスタンス化しようとしていますが、Java がインスタンス化されたオブジェクトのコンストラクターで引数を受け入れるのに苦労しています。誰か助けてください、ありがとう! プログラムは次のとおりです。
public class Box {
double width;
double height;
double depth;
Box(Box ob)
{
this.width=ob.width;
this.height=ob.height;
this.depth=ob.depth;
}
Box(double width, double height, double depth)
{
this.width=width;
this.height=height;
this.depth=depth;
}
double volume()
{
return width * height * depth;
}
}
public class BoxWeight extends Box{
double weight;
BoxWeight(BoxWeight object)
{
super(object);
this.weight=object.weight;
}
BoxWeight(double w, double h, double d, double wei)
{
super(w,h,d);
this.weight=wei;
}
}
public class Proba {
public static void main(String[] args) {
BoxWeight myBox1 = new BoxWeight();
BoxWeight myBox2 = new BoxWeight();
}
}
これで、メイン クラスの BoxWeight() コンストラクターに引数を渡そうとするたびにエラーが発生します。