![](/img/trans.png)
[英]Java error: constructor Transaction in class Transaction cannot be applied to given types
[英]Cube.java:19: error: constructor Object in class Object cannot be applied to given types;
我无法弄清楚为什么我的代码无法编译。 我不断收到不同的代码。 这是最新的:Cube.java:19: 错误:类 Object 中的构造函数 Object 不能应用于给定类型;
任何人都可以帮助我解决这个问题吗?
public class Cube
{
private double height;
private double width;
private double depth;
private double surfaceArea;
private double volume;
public Cube(double h, double w, double d)
{
super(h,w);
depth = d;
}
public void setDepth(double d)
{
depth = d;
}
public double getDepth()
{
return depth;
}
public double computeSurfaceArea()
{
height = super.getHeight();
width = super.getWidth();
surfaceArea = (2 * height * width) + (2 * width * depth) + (2 * height * depth);
return surfaceArea;
}
public double computeVolume()
{
volume= (height*width*depth);
return volume;
}
}
错误信息:
Cube.java:19: 错误:类 Object 中的构造函数 Object 不能应用于给定类型; 超级(h,w); ^ 要求:未找到参数:double,double 原因:实际和形式参数列表的长度不同
首先确保你声明了一个基类(在你的情况下我假设是框)
class Box
{
protected double height,width;
protected Box(double h,double w)
{
height=h;
width=w;
}
}
接下来确保您的多维数据集类从中扩展
class Cube extends Box
{
private double depth;
private double surfaceArea;
private double volume;
public Cube(double h, double w, double d)
{
super(h,w);
depth = d;
}
}
public Cube(double h, double w, double d)
{
height = h;
width = w;
depth = d;
}
public double computeSurfaceArea() {
surfaceArea = (2 * height * width) + (2 * width * depth) + (2 * height * depth);
return surfaceArea;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.