If I have a constructor that holds a variable. How can I call that variable in another method within the same class?
In my example below, I want the code to return false in the checkBoundaries method if the col is greater that the Columnnum that is in the constructor.
import java.util.Arrays;
class MovieSeating
{
private String[][] Seats;
public MovieSeating(int rowNum, int columnNum)
{
Seats = new String[rowNum][columnNum];
for (int r = 0; r < rowNum; r++)
{
for (int c = 0; c < columnNum; c++)
{
Seats[r][c] = "?.?";
System.out.print(Seats[r][c] + " ");
}
System.out.println("\n");
}
System.out.println("Seating is empty.");
}
public boolean checkBoundaries(int row, int col)
{
if (col < 0 || row < 0 || col >= columnNumInConstructorParameter)
{
return false;
}
else {
return true;
}
}