Chapter 7 Book Quiz Flashcards
In an array declaration, this indicates the number of elements that the array will have.
a) subscript
b) size declarator
c) element sum
d) reference variable
b) size declarator
Explanation: The size declarator specifies the number of elements the array can hold when it is declared.
Each element of an array is accessed by a number known as a(n) .
a) subscript
b) size declarator
c) address
d) specifier
a) subscript
Explanation: A subscript (or index) is the number used to access specific elements in an array.
The first subscript in an array is always .
a) 1
b) 0
c) -1
d) 1 less than the number of elements
b) 0
Explanation: Array indexing in Java is zero-based, so the first subscript is always 0.
The last subscript in an array is always .
a) 100
b) 0
c) -1
d) 1 less than the number of elements
d) 1 less than the number of elements
Explanation: The last index in an array is always the total number of elements minus one.
Array bounds checking happens .
a) when the program is compiled
b) when the program is saved
c) when the program runs
d) when the program is loaded into memory
c) when the program runs
Explanation: Java performs array bounds checking during runtime, throwing an ArrayIndexOutOfBoundsException for invalid accesses.
This array field holds the number of elements that the array has.
a) size
b) elements
c) length
d) width
c) length
Explanation: The length field of an array in Java holds its size, or the number of elements it contains.
This search algorithm steps through an array, comparing each item with the search value.
a) binary search
b) sequential search
c) selection search
d) iterative search
b) sequential search
Explanation: The sequential search algorithm examines each element in order until the target value is found or the array is fully traversed.
This search algorithm repeatedly divides the portion of an array being searched in half.
a) binary search
b) sequential search
c) selection search
d) iterative search
a) binary search
Explanation: The binary search works by dividing the array into halves, narrowing the search range with each comparison.
This is the typical number of comparisons performed by the sequential search on an array of N elements (assuming the search values are consistently found).
a) 2N
b) N
c) N/2
d) N*2
c) N/2
Explanation: On average, a sequential search examines half the elements before finding the desired value.
When initializing a two-dimensional array, you enclose each row’s initialization list in .
a) braces
b) parentheses
c) brackets
d) quotation marks
a) braces
Explanation: Each row of a two-dimensional array is initialized using braces {}.
To insert an item at a specific location in an ArrayList object, you use this method.
a) store
b) insert
c) add
d) get
c) add
Explanation: The add method with two arguments can insert an element at a specific index in an ArrayList.
To delete an item from an ArrayList object, you use this method.
a) remove
b) delete
c) erase
d) get
a) remove
Explanation: The remove method deletes an element from the ArrayList.
To determine the number of items stored in an ArrayList object, you use this method.
a) size
b) capacity
c) items
d) length
a) size
Explanation: The size method returns the number of elements currently stored in the ArrayList.
TRUE OR FALSE: Java does not allow a statement to use a subscript that is outside the range of valid subscripts for an array.
True
Explanation: Java checks array subscripts at runtime, throwing an exception for invalid accesses.
TRUE OR FALSE: An array’s size declarator can be a negative integer expression.
False
Explanation: Java does not allow negative size declarations for arrays.