小编Hoo*_*ege的帖子

在java中使用super

对于Cube课程,我试图摆脱错误:

Cube.java:12: error: constructor Rectangle in class Rectangle cannot be applied to given types;
    super(x, y);
    ^
  required: int,int,double,double
  found: int,int.......
Run Code Online (Sandbox Code Playgroud)

我知道立方体的每个面都是一个矩形,其长度和宽度需要与立方体的边相同但我不确定需要传递给Rectangle构造函数以使其长度和宽度与一个立方体的一面.

还尝试计算体积,即矩形面积乘以立方体边长度

这是Cube类

// ---------------------------------
// File Description:
//   Defines a Cube
// ---------------------------------

public class Cube extends Rectangle
{


  public Cube(int x, int y, int side)
  {
    super(x, y);
    side = super.area(); // not sure if this is right
  }


  public int    getSide()   {return side;}

  public double area()      {return 6 * super.area();}
  public double volume()    {return …
Run Code Online (Sandbox Code Playgroud)

java constructor return super

7
推荐指数
1
解决办法
465
查看次数

标签 统计

constructor ×1

java ×1

return ×1

super ×1