Array in Java MCQs Exercise II

Ques 1 Array


What will be the output of the following code?

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

A 4
B Compilation Error
C ArrayIndexOutOfBoundsException
D 0

Ques 2 Array


What will be the output of the following code?

public class Main {
    public static void main(String[] args) {
        int[] arr = new int[3];
        System.out.println(arr[0]);
    }
}

A 0
B null
C Compilation Error
D Random Value

Ques 3 Array


Which statement about arrays in Java is true?

A Arrays can hold multiple types of data.
B Arrays are objects in Java.
C The size of an array can be changed after creation.
D Arrays are dynamically sized.

Ques 4 Array


What is the length of the array declared as int[][] arr = new int[4][5];?

A 4
B 5
C 6
D 7

In Java, the length of a 2D array is determined by the number of rows. For the array declared as int[][] arr = new int[4][5];, the number of rows is 4.