go to previous page   go to home page   go to next page


No. The indicated array element (cell) does not exist.

Bounds Checking

When your program is running and it tries to acess an element of an array, the Java virtual machine checks that the array element actually exists. This is called bounds checking. If your program tries to access an array element that does not exist, the Java virtual machine will generate an:


Ordinarily, this will halt your program. Of course, as with 1D arrays, array indexes must be an integer type. It makes no sense to access gradeTable[ 3.5 ][ 2 ].

As with a 1D array, an array index may be an integer literal, a variable of integer type, a method that evaluates to an integer, or an arithmetic expression involving all of these things:

We are not likely to need a statement as complicated as the last one.


(Review: ) must the elements of a 2D array be all of the same type?