How can I and what is the best way of initialize the variables using a constructor.
For example I am trying to create a array to hold 6 Strings
class Dice{
public String [] side = new String[5];
public String name;
public Dice (String n, String [] a){
name = n;
side = a;
}
}
I have tried to set values like so:
class diceGame{
// calling main method
public static void main (String[] args){
Dice easy = new Dice("Green:",["Brain","Brain","Brain","a","a","a"]);
}
Dice easy = new Dice("Green:","Brain","Brain","Brain","a","a","a");
Dice easy = new Dice("Green:",{"Brain","Brain","Brain","a","a","a"});
In 2 occasions I get the same
error message error: illegal start of expression
and in the other
error: constructor Dice in class Dice cannot be applied to given types;
found: String,String,String,String,String,String,String
I would like to know which is the most efficient way of doing this?
Here is a previous question which made me think if there are so many ways of doing this which is actually the best?
How to initialize array in java when the class constructor has parameters?