aspose file tools*
The moose likes Beginning Java and the fly likes problem with array of objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with array of objects" Watch "problem with array of objects" New topic
Author

problem with array of objects

Simon Gouder
Greenhorn

Joined: Nov 08, 2003
Posts: 2
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

Joined: Nov 08, 2003
Posts: 2
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with array of objects