Java Arrays Quiz Form
Test your knowledge of Java arrays. Answer all questions to the best of your ability. All questions are required.
1. Which of the following is the correct way to declare an array of integers in Java?
*
int[] arr;
arr[] int;
array int arr;
int arr[];
2. What is the default value of an int array element in Java?
*
0
null
undefined
1
3. How do you determine the number of elements in an array named 'numbers'?
*
numbers.size()
numbers.length
numbers.length()
numbers.getLength()
4. What will be the output of the following code? int[] arr = {1, 2, 3}; System.out.println(arr[1]);
*
1
2
3
ArrayIndexOutOfBoundsException
5. Which statement creates an array of 5 doubles?
*
double[] arr = new double[5];
double arr = new double[5];
arr = double[5];
double arr[] = 5;
6. What happens if you try to access arr[10] in an array declared as int[] arr = new int[5];?
*
Returns 0
Compiles but throws an exception at runtime
Returns null
Compiles and runs without error
7. Which of the following is NOT a valid way to initialize an array?
*
int[] arr = new int[3];
int[] arr = {1, 2, 3};
int arr[] = new int[]{1, 2, 3};
int arr[] = new int[3] {1, 2, 3};
8. Write the code to declare and initialize a String array with the values "A", "B", and "C".
*
9. What is the index of the last element in an array of length 7?
*
7
6
1
0
10. Briefly explain the difference between an array and an ArrayList in Java.
*
Submit Quiz
Should be Empty: