
8.3 Aggregate Array Operations 473
lines 21–23, we assign element 1 to the Auto reference myCar, then call the
getGallonsOfGas method using the myCar reference.
Finally, line 26 attempts to retrieve the model of element 2; however,
because cars[2] is null, a NullPointerException is generated. Figure 8.4
shows the output of this program.
8.3 Aggregate Array Operations
Once the array is declared and instantiated, it would be convenient if we
could just use the array name to perform operations on the whole array,
such as printing the array, copying the array to another array, inputting val-
ues to the array, and so on. Unfortunately, Java does not support ...