1.
For how many integers does the following statement reserve room?
int[] value = new int[12];
Correct Answer
B. 12
Explanation
The statement "int[] value = new int[12];" reserves room for 12 integers. This is because the statement creates an array called "value" with a length of 12, which means it can hold 12 elements. Each element in the array is of type int, so the statement reserves room for 12 integers.
2.
When you declare an array __________.
Correct Answer
A. You might reserve the memory for it in the statement.
Explanation
When you declare an array, you have the option to reserve the memory for it in the statement. This means that you can specify the size or length of the array at the time of declaration, which allocates the necessary memory for storing the elements of the array. However, it is not mandatory to reserve memory at the time of declaration, as you can also dynamically allocate memory for the array later in the program. Therefore, the correct answer is "You might reserve the memory for it in the statement."
3.
An array is a list of data items that ________.
Correct Answer
C. All have the same type
Explanation
An array is a data structure that can store multiple elements of the same type. This means that all the data items within an array must have the same type, whether it is integers, strings, or any other data type. By having the same type, it allows for efficient memory allocation and easy access to the elements within the array.
4.
You reserve memory locations for an array when you ______.
Correct Answer
A. Use the keyword new
Explanation
When you use the keyword "new" in programming, it dynamically allocates memory for an array. This means that you are reserving memory locations for the array at runtime, allowing you to store and access data within the array. By using the keyword "new", you can create an array of a specific size and ensure that the necessary memory is allocated for it.
5.
Assume an array is declared as follows. Which of the following statements correctly assigns the value 80 to each of the array elements?
int[] num = new int [3];
Correct Answer
A. For (x = 0; x < 3; ++[x] = 100;
Explanation
The correct answer is the for loop "for (x = 0; x < 3; ++[x] = 100;". This loop iterates through each index of the array (x = 0, 1, 2) and assigns the value 100 to each element using the syntax ++[x] = 100. This will correctly assign the value 100 to each element of the array.
6.
In Java you can declare an array of 12 elements and initialize _____.
Correct Answer
A. All of them
Explanation
In Java, when declaring an array of 12 elements, you have the option to initialize all of them. This means that you can assign values to each element of the array during its declaration. By doing so, you ensure that all 12 elements have specific values assigned to them from the beginning.
7.
When you initialize an array by giving it values upon creation, you ________.
Correct Answer
C. Don't explicitly give the array a size
Explanation
When you initialize an array by giving it values upon creation, you don't explicitly give the array a size. This means that the size of the array is automatically determined based on the number of values provided during initialization.
8.
Suppose you have declared an array as follows;
int[] creditScores = {670, 840, 576, 740, 820}
Correct Answer
D. 5
Explanation
The given answer, 5, is the index of the last element in the array. In Java, array indices start from 0, so the first element is at index 0 and the last element is at index 4. Therefore, the correct answer is 4.
9.
Unicode value '\u0000' is also know as _____.
Correct Answer
C. Null
Explanation
The Unicode value '\u0000' is also known as "null".
10.
Array names represent
Correct Answer
D. Refrences
Explanation
Array names represent references because when an array is declared, it is actually a pointer to the first element of the array. This means that the array name holds the memory address of the first element, allowing us to access and manipulate the elements of the array using the array name. Therefore, array names act as references to the array elements.
11.
Which of the following can be used as an array subscript?
Correct Answer
A. Int
Explanation
An array subscript is used to access elements within an array. In most programming languages, including C++, the array subscript must be an integer value. Therefore, only "int" can be used as an array subscript among the given options. "double" is a floating-point data type, "string" is a sequence of characters, and "character" is a single character data type, none of which can be used as an array subscript.
12.
If you declare an array as follows, how do you indicate the final element of the array?
int[] num = new int[5];
Correct Answer
A. Num[4]
Explanation
To indicate the final element of the array, you use the index value of the last element, which in this case is num[4]. The index values start from 0, so num[4] refers to the fifth element in the array.
13.
You declare an integer array as follows, what is the value of num[4]?
int[] num = { 204, 348, 795, 111, 45, 86}
Correct Answer
D. 45
Explanation
The value of num[4] is 45. In the given code, an integer array named "num" is declared and initialized with 6 elements. The index of an array starts from 0, so num[4] refers to the fifth element in the array, which is 45.
14.
If a class named Student contains a method setID() that takes an int argument and you write an application in which you create an array of 20 Student objects named scholar, which of the following statements correctly assigns an ID number to the first Student scholar?
Correct Answer
C. Scholar[0].setID(1234)
Explanation
The correct statement that assigns an ID number to the first Student scholar is scholar[0].setID(1234). This is because scholar is an array of Student objects, and to access the first element of the array, we use the index [0]. Then, we call the setID() method on the first element to assign the ID number 1234.
15.
A parallel array is one that _____?
Correct Answer
B. Holds values that correspond to those in another array
Explanation
A parallel array is an array that holds values that correspond to those in another array. This means that the elements in the parallel array have a relationship or connection with the elements in the other array. The values in the parallel array are typically associated or linked to the values in the corresponding positions of the other array. This allows for easier access and manipulation of related data in the program.
16.
When you pass an array element to a method, the method receives ________?
Correct Answer
B. A copy of the value in the element
Explanation
When you pass an array element to a method, the method receives a copy of the value in the element. This means that any changes made to the element within the method will not affect the original array. The method operates on a separate copy of the value, allowing for independent manipulation without altering the original data.
17.
If a method should return an array to its calling method ______>
Correct Answer
B. The return type in the method header is followed by square brackets
Explanation
When a method should return an array to its calling method, the return type in the method header is followed by square brackets. This indicates that the method will return an array of a specific type. For example, if the return type is "int[]", it means that the method will return an array of integers. This is necessary because it allows the calling method to correctly receive and handle the returned array.
18.
A single array element of a primitive type is passed to a method by _____.
Correct Answer
A. Value
Explanation
When a single array element of a primitive type is passed to a method by value, it means that a copy of the value of the element is passed to the method. Any changes made to the value within the method will not affect the original value in the array.
19.
When you pass an array to a method, the method receives _____.
Correct Answer
B. The array address
Explanation
When you pass an array to a method, the method receives the memory address of the array. This means that the method can access and modify the elements of the array directly, as it has the location of the array in memory. The method does not receive a copy of the array or its elements, but rather a reference to the original array. Therefore, any changes made to the array within the method will be reflected in the original array outside of the method as well.