B
BillJosephson
Hello. I have a class which will need string arrays. Normally I declare
them as instance variables in the class. But, can these instance
variables be part of the constructor? Here is an example. (1) shows how
I usually declare and instantiate class variables. (2) shows what I
would like to do.
public class chess
{
(1)
int [][] piecesLeft = {{ 1,1,2,2,2,8},{1,1,2,2,2,8}};
String[] pieces = { "King","Queen","Bishop","Knight","Rook","Pawn"
};
// Constructors:
// default
public chess( )
{
(2)
int [][] piecesLeft = {{ 1,1,2,2,2,8},{1,1,2,2,2,8}};
String[] pieces = {"King","Queen","Bishop","Knight","Rook","Pawn"
};
}
}
I tried the code a few different ways, but jGrasp just gives me errors.
I've looked around on line but haven't been able to find this
addressed.
Thanks for any help.
them as instance variables in the class. But, can these instance
variables be part of the constructor? Here is an example. (1) shows how
I usually declare and instantiate class variables. (2) shows what I
would like to do.
public class chess
{
(1)
int [][] piecesLeft = {{ 1,1,2,2,2,8},{1,1,2,2,2,8}};
String[] pieces = { "King","Queen","Bishop","Knight","Rook","Pawn"
};
// Constructors:
// default
public chess( )
{
(2)
int [][] piecesLeft = {{ 1,1,2,2,2,8},{1,1,2,2,2,8}};
String[] pieces = {"King","Queen","Bishop","Knight","Rook","Pawn"
};
}
}
I tried the code a few different ways, but jGrasp just gives me errors.
I've looked around on line but haven't been able to find this
addressed.
Thanks for any help.