首页 > 解决方案 > 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);^ 必需:未找到参数:双重,双重原因:实际参数列表和正式参数列表的长度不同

标签: java

解决方案


首先确保你声明一个基类(在你的情况下我假设是盒子)

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;
   }
}

推荐阅读