java构造函数错误:类中的构造函数不能应用于给定的类型

我是java新手我对inheritance或构造函数知之甚少。
扩展类时是否有使用构造函数的限制(如参数数量)?
这是我的计划:

class Box { int length,breadth,height; Box(int l,int b,int h) { length=l; breadth=b; height=h; } int volume() { return length*breadth*height; } } class BoxWeight extends Box { int weight; BoxWeight(int l,int b,int h,int w) { length=l; breadth=b; height=h; weight=w; } } class BoxInheritance { public static void main(String args[]) { Box B1=new Box(5,75,4); BoxWeight B2=new BoxWeight(23,32,56,54); System.out.println("\n the volume of box1 is "+B1.volume()); System.out.println("\n the volume of box2 is "+B2.volume()); } } 

当我运行此程序时,我收到此错误:

BoxInheritance.java:29:错误:类Box中的构造函数Box不能应用于给定的类型; {^ required: int,int,int found: no arguments reason: actual and formal argument lists differ in length 1 error

我不知道错误发生在哪里。
子类构造函数是否需要与超类构造函数相同数量的参数?

你的BoxWeight类应如下所示:

 class BoxWeight extends Box { int weight; BoxWeight(int l, int b, int h, int w) { super(l, b, h); weight = w; } } 

请阅读Java中的构造函数链接。

如果派生一个只有带参数的构造函数的基类,在你的情况下是Box(int l,int b,int h) ,那么派生类需要调用一个传递所需参数的构造函数。

 BoxWeight(int l,int b,int h,int w) { super(l, b, h); // do any additional stuff } 

请记住,构造函数调用必须是构造函数中的第一个语句。