First up, your code only creates 1 StudentRecord instance, which all the Student instances use. You could fix that easily and get the project working although...
The other issue is that you have failed to use composition e.g. a Student has a StudentRecord, so you should really be creating your StudentRecord instances to be part of each Student instance by putting the code to declare and create a StudentRecord in the Student class, not in the StudentRecordExample class where the main method is. You already have the studentRecord instance variable there in the Student class, you just need to add the instantiating statement to a constructor (which is missing at the moment). Alternatively you could create the instances of each StudentRecord in the main method and pass them to each Student instance through the Student object constructors or some other method e.g. public void addStudentRecord (StudentRecord sR), but that approach isn't a very good way of doing it. The reason I mention this 2nd approach (which is not the best approach in my opinion) is that it's good practice to think of a number of different ways of coding something, and then evaluate each to see what their advantages and disadvantages are. In the above case, the second example requires 2 separate tasks to be performed and that they're performed in a specific order before you have a usable Student instance. It's an example of tight coupling between classes, and tight coupling is a bad thing. As you learn more about the Object Oriented side of programming and Java you'll come across these sorts of topics which are concerned with how to model objects and systems. Hope this all helps and isn't too confusing. On 20/11/2009, at 6:48 AM, Rammohan Vadlamani wrote: > <MyStudentRecordExampleProject2.zip> -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en
