PRACTICE • LEARN • GROW
Module 7: Arrays - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 7: Arrays - Final Quiz Progress
0 of 13 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
How are arrays represented in Java compared to C?
A.
In Java, an array is a genuine heap-allocated object with a built-in .length field and bounds checking, whereas in C it is a raw memory address
B.
In Java, arrays can grow dynamically like ArrayLists
C.
Java arrays are stored in CPU registers
D.
Java arrays have no fixed size
Explanation & Key
Correct Answer:
2
What happens when executing the following code?
int[] scores = new int[5];
System.out.println(scores[5]);
A.
Prints 0
B.
Throws ArrayIndexOutOfBoundsException at runtime
C.
Prints random garbage memory value
D.
Compile-time error
Explanation & Key
Correct Answer:
3
What is a "jagged array" in Java?
A.
An array that contains multiple primitive types simultaneously
B.
A multidimensional array where member rows have differing lengths because each row is an independent heap array object
C.
An array whose indices are negative
D.
An uninitialized array pointer
Explanation & Key
Correct Answer:
4
What is printed by this jagged array snippet?
int[][] matrix = {
{10, 20, 30},
{40, 50}
};
System.out.println(matrix.length + " " + matrix[1].length);
A.
2 3
B.
2 2
C.
5 2
D.
3 2
Explanation & Key
Correct Answer:
5
What happens when executing this array of objects snippet?
class Student {
String name = "Alice";
}
public class Test {
public static void main(String[] args) {
Student[] list = new Student[5];
System.out.println(list[0].name);
}
}
A.
Prints 'Alice'
B.
Throws NullPointerException at runtime because list[0] holds null
C.
Prints null
D.
Compile error: array uninitialized
Explanation & Key
Correct Answer:
6
What are the default values of elements in a newly allocated primitive
int[] and boolean[] array in Java?
A.
Garbage values
B.
0 and false respectively
C.
-1 and true
D.
null and null
Explanation & Key
Correct Answer:
7
Which syntax correctly retrieves the total element capacity of an array named
data in Java?
A.
data.length()
B.
data.length
C.
data.size()
D.
sizeof(data)
Explanation & Key
Correct Answer:
8
What will be printed by the following code demonstrating array reference aliasing?
int[] a = {10, 20, 30};
int[] b = a;
b[1] = 99;
System.out.println(a[0] + " " + a[1] + " " + a[2]);
A.
10 20 30
B.
10 99 30
C.
99 99 99
D.
Compile-time error
Explanation & Key
Correct Answer:
9
What will be the output of comparing two distinct arrays with identical contents?
int[] arr1 = {1, 2, 3};
int[] arr2 = {1, 2, 3};
System.out.println((arr1 == arr2) + " " + arr1.equals(arr2) + " " + java.util.Arrays.equals(arr1, arr2));
A.
true true true
B.
false false true
C.
false true true
D.
true false true
Explanation & Key
Correct Answer:
10
What is printed by this dynamically allocated jagged array loop?
int[][] triangle = new int[3][];
for (int i = 0; i < 3; i++) {
triangle[i] = new int[i + 1];
for (int j = 0; j <= i; j++) {
triangle[i][j] = i + j;
}
}
System.out.println(triangle[2][1]);
A.
1
B.
3
C.
2
D.
4
Explanation & Key
Correct Answer:
11
What will be the output of the following method call passing an array and an int primitive?
public class ArrayParamTest {
static void modify(int[] nums, int val) {
nums[0] = 88;
val = 99;
nums = new int[]{100, 200};
}
public static void main(String[] args) {
int[] myArr = {1, 2};
int myVal = 10;
modify(myArr, myVal);
System.out.println(myArr[0] + " " + myVal);
}
}
A.
1 10
B.
88 10
C.
100 99
D.
88 99
Explanation & Key
Correct Answer:
12
Which of the following array declarations causes a compile-time syntax error in Java?
A.
int[] a = new int[5];
B.
int a[] = new int[]{1, 2, 3};
C.
int[] a = new int[3]{1, 2, 3};
D.
int[][] a = new int[3][];
Explanation & Key
Correct Answer:
13
What will be printed by the following 2D array nested enhanced for-loop?
int[][] grid = {{1, 2}, {3, 4, 5}};
int total = 0;
for (int[] row : grid) {
for (int val : row) {
total += val;
}
}
System.out.println(total);
A.
10
B.
15
C.
12
D.
0
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong