| Java Arrays, Objects, Methods | CS 161 - Java |
int[] grades; grades = new int[60];
Arrays of Objects are initialized to null
Student[] students; students = new Student[60];
The students array has been declared and instantiated, but not yet initialized: no Student object references have been assigned to the array elements.
To initialize the array elements, you need to instantiate each individually:
for (int nextStudent = 0; nextStudent < 10; nextStudent++ ) { students[nextStudent] = new CSStudent(); }
|
jwd |