Array and Array Operations | Data Structure MCQs

1.

What are the advantages of arrays?

   A.) Easier to store elements of same data type
   B.) Used to implement other data structures like stack and queue
   C.) Convenient way to represent matrices as a 2D array
   D.) All of the mentioned

Answer: Option 'D'

Arrays are simple to implement when it comes to matrices of fixed size and type, or to implement other data structures.

2.

Which of these best describes an array?

   A.) A data structure that shows a hierarchical behavior
   B.) Container of objects of similar types
   C.) Container of objects of mixed types
   D.) All of the mentioned

Answer: Option 'B'

Container of objects of similar types
Array contains elements only of the same type.

3.

Which of the following is a correct way to declare a multidimensional array in Java?

   A.) int[][] arr;
   B.) int arr[][];
   C.) int []arr[];
   D.) All of the mentioned

Answer: Option 'D'

All the options are syntactically correct.

4.

What is the output of the following piece of code?

public class array
{
	public static void main(String args[])
	{
		int []arr = {1,2,3,4,5};
		System.out.println(arr[5]);
	}
}

   A.) 5
   B.) 4
   C.) ArrayIndexOutOfBoundsException
   D.) InavlidInputException

Answer: Option 'C'

Trying to access an element beyond the limits of an array gives ArrayIndexOutOfBoundsException.

5.

When does the ArrayIndexOutOfBoundsException occur?

   A.) Compile-time
   B.) Run-time
   C.) Not an error
   D.) None of the mentioned

Answer: Option 'B'

ArrayIndexOutOfBoundsException is a run-time exception and the compilation is error-free.

Array and Array Operations | Data Structure MCQs Download Pdf