[Solved] Java Creating Objects at Runtime in a For Loop


You want to use a data structure to store a sequence of objects. For example, an array could do this:

 Fruit banana[] = new Fruit[10];
 for (int i = 0; i < 10; i++){
       banana[i] = new Fruit();
 }

This creates 10 objects of type Fruit in the banana array, I can access them by calling banana[0] through banana[9]

solved Java Creating Objects at Runtime in a For Loop