我有一个魔方课程,内容如下:
public class Rubik{
private int[][][] grid;
protected Face[] cube;
protected Face up;
protected Face left;
protected Face front;
protected Face right;
protected Face down;
protected Face back;
private static String dots = "......";
private String output;
//Constructor
public Rubik(int[][][] grid){
int[][][] copy_grid = new int[6][3][3];
for (int k = 0; k < 6; k++){
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++)
copy_grid[k][i][j] = grid[k][i][j];
}
}
this.grid = copy_grid;
this.up = new Face(grid[0]);
this.left = new Face(grid[1]);
this.front = new Face(grid[2]);
this.right = new Face(grid[3]);
this.down = new Face(grid[4]);
this.back = new Face(grid[5]);
this.cube = new Face[]{this.up, this.left, this.front, this.right, this.down, this.back};
}
我正在尝试创建一个扩展 Rubik 的 RubikRight 类,并且 RubikRight 的方向是原始 Rubik 的右面现在面向前面。这就是我为 RubikRight 定义构造函数的方式:
public class RubikRight extends Rubik{
//Constructor
public RubikRight(int[][][] grid){
int[][][] copy_grid = new int[6][3][3];
for (int k = 0; k < 6; k++){
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++)
copy_grid[k][i][j] = grid[k][i][j];
}
}
this.grid = copy_grid;
this.up = new Face(grid[0]);
this.left = new Face(grid[2]);
this.front = new Face(grid[3]);
this.right = new Face(grid[5]);
this.down = new Face(grid[4]);
this.back = new Face(grid[1]);
this.cube = new Face[]{this.up, this.left, this.front, this.right, this.down, this.back};
}
但是,我收到错误消息
Constructor Rubik in class Rubik cannot be applied to the given type;
public RubikRight(int[][][] grid){
^
required: int[][][]
found: no arguments
reason: actual and formal argument lists differ in length
1 error
我可以知道为什么我似乎不能那样定义 RubikRight 吗?