java显式调用_java-必须显式调用另一个构造函数

为什么Eclipse总是在构造函数上给我错误:

public DenseBoard(Tile t[][]){

Board myBoard = new DenseBoard(t.length, t[0].length);

}

错误为:隐式超级构造函数Board()未定义.必须显式调用另一个构造函数

类密集板

package Game2048;

// Tracks the positions of an arbitrary 2D grid of Tiles. DenseBoard

// uses an internal, multi-dimensional array to store the tiles and

// thus has a O(R * C) memory footprint (rows by columns).

public class DenseBoard extends Board {

// Build a Board of the specified size that is empty of any tiles

public DenseBoard(int rows, int cols){

super(rows, cols);

}

// Build a board that copies the 2D array of tiles provided Tiles

// are immutable so can be referenced without copying but the a

// fresh copy of the 2D array must be created for internal use by

// the Board.

public DenseBoard(Tile t[][]){

Board myBoard = new DenseBoard(t.length, t[0].length);

}

类板

package Game2048;

public abstract class Board{

protected int rows;

protected int cols;

public Board(int rows, int cols){

this.rows = rows;

this.cols = cols;

}

// Create a distinct copy of the board including its internal tile

// positions and any other state

public abstract Board copy();

// Return the number of rows in the Board

public abstract int getRows();

// Return the number of columns in the Board

public abstract int getCols();

// Return how many tiles are present in the board (non-empty spaces)

public abstract int getTileCount();

// Return how many free spaces are in the board

public abstract int getFreeSpaceCount();

// Get the tile at a particular location

public abstract Tile tileAt(int i, int j);

// true if the last shift operation moved any tile; false otherwise

public abstract boolean lastShiftMovedTiles();

// Return true if a shift left, right, up, or down would merge any

// tiles. If no shift would cause any tiles to merge, return false.

// The inability to merge anything is part of determining if the

// game is over.

public abstract boolean mergePossible();

// Add a the given tile to the board at the "freeI"th free space.

public abstract void addTileAtFreeSpace(int freeI, Tile tile);

// Shift the tiles of Board in various directions. Any tiles that

// collide and should be merged should be changed internally in the

// board. Shifts only remove tiles, never add anything. The shift

// methods also set the state of the board internally so that a

// subsequent call to lastShiftMovedTiles() will return true if any

// Tile moved and false otherwise. The methods return the score

// that is generated from the shift which is the sum of the scores

// all tiles merged during the shift. If no tiles are merged, the

// return score is 0.

public abstract int shiftLeft();

public abstract int shiftRight();

public abstract int shiftUp();

public abstract int shiftDown();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值