Why is Eclipse keeps giving me error on the constructor:
public DenseBoard(Tile t[][]){
Board myBoard = new DenseBoard(t.length, t[0].length);
}
Just to point out
public DenseBoard(Tile t[][]) {
Board myBoard = new DenseBoard(t.length, t[0].length);
}
myBoard
is local variable, you will not be able to refer it when you create a new object using new DenseBoard(Tile t[][])
.
You can do it in 2 ways.
public DenseBoard(Tile t[][]) {
super(t.length, t[0].length); // calling super class constructor
}
// or
// I would prefer this
public DenseBoard(Tile t[][]) {
this(t.length, t[0].length); // calling DenseBoard(int rows, int cols) constuctor, which is internally passing the value to super class.
}