#''illegal start of expression'' when trying to create a chess java program

15 messages · Page 1 of 1 (latest)

summer wadi
#

When I try to create a chess java program (my code so far is below) it says "illegal start of expression" how do I fix it?
Heres my code:

public class Spot {
    private Piece piece;
    private int x;
    private int y;

    public Spot(int x, int y, Piece piece)
    {
        this.setPiece(piece);
        this.setX(x);
        this.setY(y);
    }

    public Piece getPiece()
    {
        return this.piece;
    }

    public void setPiece(Piece p)
    {
        this.piece = p;
    }

    public int getX()
    {
        return this.x;
    }

    public void setX(int x)
    {
        this.x = x;
    }

    public int getY()
    {
        return this.y;
    }

    public void setY(int y)
    {
        this.y = y;
    }
}
balmy estuaryBOT
#

Hey, @summer wadi!
Please remember to /close this post once your question has been answered!

chilly solstice
#

you should provide the full error message. It should also provide you with information where the error occurs

summer wadi
#

it doesnt provide any other info all it says is "illegal start of expression". im using codiva.io online java compiler, btw

chilly solstice
#

you can't define a class inside a method

summer wadi
#

oh

chilly solstice
#

if you're seeking help please provide your full code. the code you posted was without issue, the screenshot showed problematic code.

#

that way you're making it harder to help you

summer wadi
#

but that was the only code ive written so far

#

also how do i define multiple classes together

chilly solstice
#

yes but that's not the only code that's run

summer wadi
#

sry im just new to java

chilly solstice
#

usually, multiple files. one file per class

#

there's also inner classes, you should be able to find out about them by searching for the term online