Chapter 8 - Multiple Choice Flashcards
- What are the valid ways to declare an integer array named a? (Check all that apply.)
❑ int [ ] a;
❑ int a[ ];
❑ array int a;
❑ int array a;
int []a and int a[]
- What is the index of the first element of an array?
❑ –1
❑ 0
❑ 1
0
- An array a has 30 elements; what is the index of its last element?
❑ 29
❑ 30
❑ 31
29
- What is the default value of the elements in an array of ints after declaration and instantiation of the array?
❑ 0
❑ null
❑ undefined
0
- How do you access the element of array a located at index 6?
❑ a{6}
❑ a( 6 )
❑ a[6]
a [6]
- Which of the following assertions is true?
❑ An array cannot be sized dynamically.
❑ An array can be sized dynamically, but cannot be resized without instantiating it again.
❑ An array can be sized dynamically and can also be resized without instantiating it again.
An array can be sized dynamically, but cannot be resized without instantiating it again
- How do you retrieve the number of elements in an array a?
❑ a . length( )
❑ a . length
❑ a . size( )
❑ a . size
a.length
- All the elements of an array must be of the same data type.
❑ true
❑ false
true
- Array aggregate assignment is possible in Java.
❑ true
❑ false
false
- Aggregate comparison of arrays is possible in Java.
❑ true
❑ false
false
(Explanation:
• Aggregate comparison operation is not allowed in java to compare each individual elements one array with other.
• To compare elements from one array to another array must be done with comparison operators (, <=,>=, ==, ! =)
• For example, int a[]={1,2,3,4,5};
• int b[]={1,2,3,4,5};
• a==b is incorrect comparison to check if two array contains same elements.
• Therefore, aggregate comparison is possible in java is incorrect statement.)
- An array can be returned by a method.
❑ true
❑ false
true
- A Sequential Search on a sorted array can be written more efficiently than a Sequential Search on an unsorted array.
❑ true
❑ false
false
(Explanation:
- Searching is a process to find a given key value in an array.
- In a sequential search process, each element of the array is searched from starting element to last element.
- Whether array is sorted or unsorted, each element of the array is searched with key element to find a match if key is in the array or not.
- The time-complexity of the sequential search is O(n)
- Therefore, the statement sequential search on a sorted array is faster than on an unsorted array is incorrect.)