Answers 100% Pass
What is an array in Java?
A) A collection of variables of different types
B) A dynamically growing data structure
✔✔C) A fixed-size collection of elements of the same type
D) A method to store multiple objects in a single variable
How do you declare an array in Java?
✔✔A) `int[] numbers;`
B) `array<int> numbers;`
C) `int numbers = new array[];`
D) `numbers = int[10];`
What is the default value of an array element of type `int`?
A) `1`
✔✔B) `0`
C) `null`
1
,D) `undefined`
Which of the following correctly initializes an array?
A) `int numbers = new int(5);`
B) `int numbers[] = {5, 10, 15};`
✔✔C) `int[] numbers = {5, 10, 15};`
D) `new int numbers = [5, 10, 15];`
How do you determine the size of an array in Java?
A) `array.length()`
✔✔B) `array.length`
C) `sizeOf(array)`
D) `array.getSize()`
What will happen if you access an index that is out of bounds in an array?
A) The value `0` is returned
B) The program skips the statement
✔✔C) A `ArrayIndexOutOfBoundsException` is thrown
2
,D) The last element of the array is accessed instead
Which statement correctly copies an array in Java?
A) `int[] copy = original;`
✔✔B) `System.arraycopy(original, 0, copy, 0, original.length);`
C) `copy = newArray(original);`
D) `copy = duplicate(original);`
How can you iterate through an array using a for-each loop?
✔✔A) `for (int num : numbers) { System.out.println(num); }`
B) `for each (int num in numbers) { System.out.println(num); }`
C) `for (int i = 0; i < numbers.length; i++) { System.out.println(numbers[i]); }`
D) `foreach (int num : numbers) { System.out.println(num); }`
What is the starting index of an array in Java?
A) `1`
✔✔B) `0`
C) `-1`
3
, D) `Depends on array type`
Which statement about multidimensional arrays is correct?
✔✔A) They are arrays that contain other arrays as elements
B) They must always have the same number of columns in each row
C) They can store elements of different data types
D) They do not require initialization
How do you declare a two-dimensional array?
A) `int array[][] = new int[3,3];`
B) `int array = new int[3][3];`
✔✔C) `int[][] array = new int[3][3];`
D) `array<int>[3][3] numbers;`
Which method is used to sort an array in Java?
✔✔A) `Arrays.sort(array);`
B) `sort(array);`
C) `array.sort();`
4