
9.2 Accessing Multidimensional Array Elements 579
There are three rows in cars: the first row has three columns, and the second
and third rows have two columns each. Line 22 retrieves the array element
at row 1 and column 0—here sportsCar—and assigns it to the Auto object
reference retrievedCar, which is then printed at lines 25–26, where toString
is called implicitly. Figure 9.5 shows the output of this example.
1 /* Working with a Two-Dimensional Array of Objects
2 Anderson, Franceschi
3 */
4
5 public class TwoDimAutoArray
6 {
7 public static void main( String []args )
8 {
9 // instantiate several Auto object references
10 Auto sedan1 = new Auto( "BMW"