Font size
WorksheetsJava Arrays Quiz
Total questions: 10
Worksheet time: 8mins
What does an array in Java do?
Stores multiple elements of different data types.
Stores multiple elements of the same data type (correct)
Stores a single element of a data type.
Does not allow index-based access.
What is the default value of an integer array in Java when it's created but not initialized?
null
0 (correct)
undefined
-1
Which of the following is the correct way to declare and initialize an array in Java?
int[] arr = new int[5]; (correct)
int arr[] = new int();
int arr = new int[5];
int arr = [5];
In an array int[] arr = {10, 20, 30, 40, 50};, what will arr[3] return?
40 (correct)
30
50
20
Which of the following is true about the length property of an array in Java?
It is a method to get the number of elements in an array.
It is a property that returns the total number of elements in an array (correct)
It returns a fixed value of 10 for every array.
It returns the data type of the array.
What will happen if you try to access an array element with an invalid index?
The program will automatically fix the index.
An exception will be thrown (correct)
The program will print a default value.
The index will be adjusted automatically.
Which loop is best suited to iterate over all elements in an array without using the index?
for loop
for-each loop (correct)
while loop
do-while loop
What will the following code print: int[] arr = {5, 10, 15}; System.out.println(arr[1]);?
5
10 (correct)
15
Array out of bounds error
Which of the following is the correct method to find the minimum value in an array in Java?
Arrays.min(array);
array.min();
You must implement your own method to find the minimum value. (correct)
array.getMin();
In a for loop, what is the condition to iterate over all elements of an array arr?
