您好,我正在尝试从扩展其超类及其构造函数 super 的类中实例化一个对象,但在 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() 构造函数时,都会出现错误。