This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem with array of objects
 
Similar Threads
Programming help
Array doubt
ExamCram Qts
type safe enum
Question on Multidimensional Array