1.
True or False: Arrays cannot be passed as parameters into methods, but their elements can be passed individually.
Correct Answer
B. False
Explanation
Arrays can be passed as parameters into methods. When an array is passed as a parameter, the method can access and manipulate the elements of the array directly. This allows for more efficient and concise code, as the entire array can be processed within the method rather than passing each element individually.
2.
Two-dimensional arrays are in ____ form.
Correct Answer
table
Explanation
Two-dimensional arrays are in table form because they are organized in rows and columns, similar to a table. Each element in the array can be accessed using two indices, one for the row and one for the column. This allows for efficient storage and retrieval of data in a structured manner, making it easier to work with large sets of data.
3.
True or False: The following array is of type String: String[] integers = new String[10];
Correct Answer
A. True
Explanation
The given array declaration "String[] integers = new String[10]" indicates that the array is of type String. The keyword "String" before the square brackets [] specifies the type of elements that the array can hold. Therefore, the statement "The following array is of type String" is true.
4.
True or False: The last index of the array above is 10.
Correct Answer
B. False
Explanation
The last index of an array is always one less than the length of the array. Therefore, if the last index of the array is 10, it means that the array has a length of 11. However, since the given answer is False, it implies that the last index of the array is not 10.
5.
One-dimensional arrays are in ____ form.
Correct Answer
list
Explanation
One-dimensional arrays are typically represented in the form of a list. A list is a data structure that allows multiple values to be stored in a single variable. In the context of arrays, a list is used to store a sequence of elements in a linear manner. Each element in the list can be accessed using its index value, which represents its position in the array. Therefore, the correct answer is "list".
6.
How many dimensions are in the following array: int[][][][][][] ndims = new int[5][5][5][5][5][5];
Correct Answer
6
Explanation
The given array "ndims" is declared with six sets of brackets, indicating six dimensions. Each set of brackets represents a separate dimension in the array. Therefore, the array has a total of six dimensions.
7.
True or False: An array in Java can have any number of dimensions.
Correct Answer
A. True
Explanation
An array in Java can have any number of dimensions, meaning it can be one-dimensional, two-dimensional, three-dimensional, and so on. This allows for flexibility in storing and accessing data in a structured manner. Whether it is a single row or column, a matrix, or a multi-dimensional structure, Java arrays can accommodate any number of dimensions based on the programmer's requirements.
8.
An exception is thrown when an array ____ goes out of bounds.
Correct Answer
index
Explanation
An exception is thrown when an array index goes out of bounds. This means that the index being accessed is either too small (less than 0) or too large (greater than or equal to the size of the array). This can happen when trying to access an element that does not exist in the array, causing the program to throw an exception to handle this error condition.
9.
True or False: Multidimensional arrays are different from one-dimensional arrays in that they do not have a fixed number of components.
Correct Answer
B. False
Explanation
False. Multidimensional arrays do have a fixed number of components. The main difference between multidimensional and one-dimensional arrays is that multidimensional arrays have multiple dimensions or levels, while one-dimensional arrays have only one dimension or level. Each dimension in a multidimensional array has a fixed number of components, which determines the size and shape of the array.
10.
True or False: As with other arrays, you can use the operator new to instantiate multidimensional arrays.
Correct Answer
A. True
Explanation
You can use the operator new to instantiate multidimensional arrays just like you would with other arrays. This means that you can dynamically allocate memory for a multidimensional array using the new operator and then access and manipulate its elements.