the class is the same.

but there are two methods:

first method:
if simply returns a string.

public String FindPiece(String chessPiece) {
		return name;
	}

name. is a constructor variable. it is a name of the chess piece

public Pawn(String name){
	this.name=name;
}

second method
public boolean isMoveValid(ChessPiece[][] pieces, int columnStart, int rowStart, int columnEnd, int rowEnd) {

if( columnEnd==rowEnd && (pieces[rowStart][columnStart].FindPiece(chessPiece).charAt(0)!=pieces[rowStart+1][columnStart-1].FindPiece(chessPiece).charAt(0)) || pieces[rowStart][columnStart].FindPiece(chessPiece).charAt(0)!=pieces[rowStart+1][columnStart+1].FindPiece(chessPiece).charAt(0) || (pieces[rowStart][columnStart].FindPiece(chessPiece).charAt(0)!=pieces[rowStart-1][columnStart-1].FindPiece(chessPiece).charAt(0) || pieces[rowStart][columnStart].FindPiece(chessPiece).charAt(0)!=pieces[rowStart-1][columnStart+1].FindPiece(chessPiece).charAt(0))){
	  	valid5=true;
}
	else{
		valid5=false;
}

}

as you can see in the condition. the FindPiece method is inside the "isMoveValid" method.

is that legal?

You can call methods from inside other methods.

No it is not inside it. What is done you call FindPiece. You can call it from wherever you want. So you are calling it from inside the method. You can call methods inside other methods:

public void p1() {

}
public void p2() {
  
}
public void p3() {
  p1();
  p2();
}

What is done, the ChessPiece [][] pieces is an array, the pieces[][] is a ChessPiece. So you can call its method:
pieces[row][col].FindPiece(chessPiece)
And since it returns a String then this is a String:
pieces[row][col].FindPiece(chessPiece)
So you can do this:
pieces[row][col].FindPiece(chessPiece).charAt(0)

alright, thats good to know. thank you guys.. i was worried i made a mistake

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.