Multiple Choice Questions - Java Arrays
1. Java does not allow arrays of lenght zero.
A) True
B) False
2. Java array indices start at . . . . .
A) 0
B) 1
3. int[][] myArray = new int[4][5];
This above declaration constructs an array myArray of . . . . elements, where each element is an array (row) of . . . . int values.
A) 5, 4
B) 4, 5
C) 4, 4
D) 5, 5
4. Arrays in Java are dynamically allocated using the . . . . operator.
A) create
B) dynamic
C) arrayList
D) new
5. Because Java does not support pointers, Java array elements are accessed only through indexes.
A) True
B) False
6. If an index value is less than 0 or greater than or equal to 'array name'.length in an array element access expression, an . . . . . . is thrown.
A) ArrayOutOfBoundsException
B) ArraysIndexOutOfBoundsException
C) ArrayIndexOutOfBoundsException
D) ArrayIndexIsOutOfBoundsException
7. Which of these array declaration statements are not legal?
(a) int[] i[] = { { 1, 2 }, { 1 }, {}, { 1, 2, 3 } };
(b) int x[] = new int[2] {1, 2};
(c) int x[][] = new int[][] { {1, 2, 3}, {4, 5, 6} };
(d) int x[][] = { { 1, 2 }, new int[ 2 ] };
(e) int x[4] = { 1, 2, 3, 4 };
8. To declare a one-dimensional array, you will use this general form
A) type array-name[] = new [size];
B) type array-name[size] = new type[];
C) type array-name[] = new type[size];
D) type array-name[] = type[size];
9. The ith element in the array has an index . . . .
A) i
B) i-1
C) i+1
D) none of above
10. In Java, each array object has a final field named . . . . that stores the size of the array.
A) width
B) size
C) length
D) distance
Answers