ITP 120 - Chapter 7 Part 1 QUIZ
What will be returned from the following method? public static float[] getValue(int x)
An array of float values
It is common practice to use a ________ variable as a size declarator.
final
Each array in Java has a public field named ________ that contains the number of elements in the array.
length
To return an array of long values from a method, use this as the return type for the method.
long[]
What do you call the number that is used as an index to pinpoint a specific element within an array?
subscript
What would be the results after the following code was executed? int[] x = (23, 55, 83, 19); int[] y = (36, 78, 12, 24); for(int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x [a]; }
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
By default, Java initializes array elements with what value?
0
Subscript numbering always starts at what value?
0
If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?
0 through 14
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};
A reference to the String "ghi"
What do you normally use with a partially-filled array?
An accompanying integer value that holds the number of items stored in the array
What will be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5};
An array of 6 values ranging from 0 through 5 and referenced by the variable x will be created.
What will be the results of the following code? final int ARRAY_SIZE = 5; float[] x = float[ARRAY_SIZE]; for(int i = 1, i <= ARRAY_SIZE; i++) { x[i] = 10.0; }
An error will occur when the program runs.
In memory, an array of String objects:
consists of elements, each of which is a reference to a String object
Which of the following for loops is valid, given the following declaration? String[] names = {"abc", "def", "ghi", "jkl"};
for (int i = 0; i < names.length; i++) System.out.println(names[i].length());
Java performs ________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.
array bounds checking
What will be the value of x[1] after the following code is executed? int[] x = {22, 33, 44}; arrayProcess(x[1]); ... public static void arrayProcess(int a) { a = a + 5; }
33
What will be the value of x[1] after the following code is executed? int[] x = {22, 33, 44}; arrayProcess(x); ... public static void arrayProcess(int[] a) { for(int k = 0; k < 3; k++) { a[k] = a[k] + 5; } }
38
What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[] x = new int[SUB]; int y = 20; for(int i = 0; i < SUB; i++) { x[i] = y; y += 5; }
60
When an array is passed to a method:
all of these