Object creation using abstraction fails, probably a simple fix I don't see

New to abstraction and constructors. I feel like I am missing something obvious.

I have an abstract class Piece, this is a constructor:

public abstract class Piece {

    private int[] location = new int[2];
    private final char color;

    public Piece(char color, int[] location) {
        this.location = location;
        this.color = color;
    }
}

      

I have a class that extends Piece:

public class Bishop extends Piece{

    public Bishop(char color, int[] location) {
        super(color, location);
    }
}

      

And I am trying to test this. However, the following code gives errors illegal execution of expression, illegal execution of type, absence of ';'

public class testing {
    Piece blackBishop = new Bishop('b', {0,0});
}

      

All of these files are in one package. After searching for a solution for several hours, I decided to ask for help. Please let me know what I did wrong.

+3


source to share


1 answer


{0,0}

can only be used by itself when you declare an int ( int[] var = {0,0};

) array variable .

Edit

Piece blackBishop = new Bishop('b', {0,0});

      



to

Piece blackBishop = new Bishop('b', new int[] {0,0});

      

+4


source







All Articles