• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with array of objects

 
Simon Gouder
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am havin problems with the following code and have spent already spent hours but got nowhere. can somebody help me pls??
why is all the values in the element objects, equal to the last code entered.
the code is
Scores myScores[] =new Scores[10]; // Scores is class
for(int i =0; i < myScores.length ; i++)
{
myScores[i] =new Scores();
System.out.print("Score code " + i + " : ");
myScores[i].setcCode(Keyboard.readString().toUpperCase());
// keyboard is a class for keyboard input
}
 
Simon Gouder
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Charles for the reply. Yes this is an assignment, however I have managed to find the problem. My problem was that setcCode() method sets the value of a member variable within the class whixh was set to static.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic