I am trying to make an array of objects. I have Two classes, the main and another class for the methods. The one i am running the program in is TestTrivia, the class with all the methods for TestTrivia is Question. Constructor for this class is
public Question()
{
question = “null”;
answer = “null”;
pointValue = 0;
}
i am trying to do something like this
Person personArray[] = new Person[5];
for(int i=0; i< personArray.length; i++)
{
personArray[i] = new Person();
}
So i have tried
Question QuestionArray[] = new Question[5];
for(int i=0; i< QuestionArray.length; i++)
{
QuestionArray[i] = new Question();
}
I have tried to use it in both classes, the main and the one full of methods. It should go into the main class correct? The error i am getting is the whole for statement is underlined and says: illegal start type cannot find symbol symbol: class i location: class triviagame.TriviaGame package QuestionArray does not exist
triviagame is the package name, “TriviaGame” is the class name, “Question” is another class name.
The loop code needs to be within a method, like
main.Also, if they are not in the same package, you will need to import classes not in the “current” package. For example, if
Questionis in the default package, it will need to be imported into theTriviaGameclass.If the
Questionclass is in thetriviagamepackage as well, the import is unnecessary.