java - Cube.java:19:错误:类 Object 中的构造函数 Object 不能应用于给定类型;
问题描述
我无法弄清楚为什么我的代码无法编译。我不断收到不同的代码。这是最新的:Cube.java:19:错误:类 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);^ 必需:未找到参数:双重,双重原因:实际参数列表和正式参数列表的长度不同
解决方案
首先确保你声明一个基类(在你的情况下我假设是盒子)
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;
}
}
推荐阅读
- python - 从 python 上传到 BigQuery 时,某些行出现 ASCII 0 错误
- python - 将项目文件夹推送到 GitHub 的最佳方法
- javascript - Javascript中的深度相等函数错误
- java - 将 jar 提取到文件夹,而不是再次制作 jar 不起作用
- python - 不支持的格式,或损坏的文件:预期的 BOF 记录;找到 b'\n\n\n\n\n\n
我做错了什么。我试图从我的 Github 解析 Excel 文件,但出现错误:
Unsupported format, or corrupt file: Expected BOF record; found b'\n\n\n\n\n\n<!
. 我在笔记本电脑上的 Spyder 和 Google Colab 中进行了这些操作,得到了同- haskell - 无法在 ghci haskell 中加载我自己的模块
- grails - 此构建中使用了弃用的 Gradle 功能,使其与 Gradle 6.0 不兼容,并且找不到 Groovy Jar
- python - 如何动态存储和执行方程和函数
- java - quarkus 中的程序化运行时注入/自动装配
- c# - 如何更新所选图像的图像(onclick)?