[ Team LiB ] 4 Declarations and Access
[ Team LiB ] 4 Declarations and Access Control 4.1 (d) In Java, arrays are objects. Each array object has a final field named lengththat stores the size of the array. 4.2 (a) Java allows arrays of length zero. Such an array is passed as an argument to the main() method when a Java program is run without any program arguments. 4.3 (c) The [] notation can be placed both before and after the variable name in an array declaration. Multidimensional arrays are created by constructing arrays that can contain references to other arrays. The expression new int[4][] will create an array of length 4, which can contain references to arrays of int values. The expression new int[4][4] will create the same array, but will in addition create four more arrays, each containing four int values. References to each of these arrays are stored in the first array. The expression int[][4] will not work, because the arrays for the dimensions must be created from left to right. 4.4 (b) and (e) The size of the array cannot be specified as in (b) and (e). The size of the array is given implicitly by the initialization code. The size of the array is never specified in the declaration of an array reference. The size of an array is always associated with the array instance, not the array reference. 4.5 (e) The array declaration is valid and will declare and initialize an array of length 20 containing int values. All the values of the array are initialized to their default value of 0. The for loop will print all the values in the array, that is, it will print 0 twenty times. Page 601
Note: If you are looking for good and quality webspace to host and run your java application check professional java hosting services