Chapter 8 - Multiple Choice Flashcards

1
Q
  1. 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;

A

int []a and int a[]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. What is the index of the first element of an array?

❑ –1

❑ 0

❑ 1

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. An array a has 30 elements; what is the index of its last element?

❑ 29

❑ 30

❑ 31

A

29

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. What is the default value of the elements in an array of ints after declaration and instantiation of the array?

❑ 0

❑ null

❑ undefined

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. How do you access the element of array a located at index 6?

❑ a{6}

❑ a( 6 )

❑ a[6]

A

a [6]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. 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.

A

An array can be sized dynamically, but cannot be resized without instantiating it again

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. How do you retrieve the number of elements in an array a?

❑ a . length( )

❑ a . length

❑ a . size( )

❑ a . size

A

a.length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. All the elements of an array must be of the same data type.

❑ true

❑ false

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Array aggregate assignment is possible in Java.

❑ true

❑ false

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Aggregate comparison of arrays is possible in Java.

❑ true

❑ false

A

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.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. An array can be returned by a method.

❑ true

❑ false

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. A Sequential Search on a sorted array can be written more efficiently than a Sequential Search on an unsorted array.

❑ true

❑ false

A

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.)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly