So I have an array of objects, 500 to be exact, that i've declared in my code.
I ran a for loop from int i = 0 to i < 500; and was expecting all the objects to be initialized or constructed. I checked a member data of array[499] and since it returned true, it was constructed. But for some odd reason 500 gave me an error, which i take as the 500th element was not constructed. Can someone please explain to me the for loop mechanics, and why it didn't construct? I've looked at other posts and saw people doing the same thing and didn't bring up any error.
I'm not sure whats the problem with my code, please help. First time SO question. Sorry in advance if i'm asking too simple of a question.
Here's two snippits of my code/execution.
Here's my code incase the link doesn't work:
public class FinalProject {
public static void main(String[] args) {
Sample[] library = new Sample[500];
for(int i = 0; i < library.length; i++)
{
library[i] = new Sample();
}
System.out.println("Availability of index 1: " + library[499].getAvailability());
}
}