7.4.1 Creating and Initializing an Array
The application of Fig. 7.2 uses keyword new
to create an array of 10 int
elements, which are initially zero (the default initial value for int
variables). Line 9 declares array
—a reference capable of referring to an array of int
elements—then initializes the variable with a reference to an array object containing 10 int
elements. Line 11 outputs the column headings. The first column contains the index (0–9) of each array element, and the second column contains the default initial value (0) of each array element.
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.