Topic : ARRAYS
1. How do you declare a single-dimensional array of integers in Java?
a) `int[] arr = new int[5];`
b) `int arr = new int[5];`
c) `array int arr = new int[5];`
d) `int arr[] = new int[]{1, 2, 3};`
**Answer:** a) `int[] arr = new int[5];`
2. Which statement correctly initializes a two-dimensional array of size 3×3?
a) `int[][] arr = new int[3][3];`
b) `int[][] arr = new int[3,3];`
c) `int arr[][] = new int[][]{ {1, 2, 3}, {4, 5, 6} };`
d) `int arr = new int[3][3];`
**Answer:** a) `int[][] arr = new int[3][3];`
3. How can you find the length of a one-dimensional array `arr`?
a) `[Link]`
b) `length(arr)`
c) `[Link]()`
d) `len(arr)`
**Answer:** a) `[Link]`
***
### Decision-Making and Looping with Arrays
4. What is the output of this code snippet?
```java
int[] arr = {10, 20, 30};
for (int i = 0; i < [Link]; i++) {
[Link](arr[i]);
}
```
a) 10 20 30
b) 0 1 2
c) Error
d) NullPointerException
**Answer:** a) 10 20 30
5. Which control statement is used to exit from a loop prematurely?
a) `break`
b) `continue`
c) `return`
d) `exit`
**Answer:** a) `break`
***
### Assertion–Reasoning Questions
6. **Assertion (A):** The default size of a Java array must be specified during initialization.
**Reason (R):** If size is not specified, the array remains uninitialized and throws an error
when accessed.
a) Both A and R are true, and R explains A.
b) Both A and R are true, but R does not explain A.
c) A is true, R is false.
d) A is false, R is true.
**Answer:** d) A is false, R is true.
*(Arrays can be declared without size initially using initializers, so size is not mandatory during
declaration)*
7. **Assertion (A):** In Java, multi-dimensional arrays are actually arrays of arrays.
**Reason (R):** Java implements 2D arrays as arrays where each element is an array itself.
a) Both A and R are true, and R explains A.
b) Both A and R are true, but R does not explain A.
c) A is true, R is false.
d) A is false, R is true.
**Answer:** a) Both A and R are true, and R explains A.
8. **Assertion (A):** Rows in a two-dimensional array can have different lengths in Java.
**Reason (R):** Java supports jagged arrays where each row can have a different number of
columns.
a) Both A and R are true, and R explains A.
b) Both A and R are true, but R does not explain A.
c) A is true, R is false.
d) A is false, R is true.
**Answer:** a) Both A and R are true, and R explains A.
***
### More Arrays Concepts
9. Which of the following is a correct way to declare a 2D array with 3 rows and 4 columns?
a) `int[][] arr = new int[3][4];`
b) `int[][] arr = new int[4][3];`
c) `int arr[][] = new int[3][4];`
d) Both a and c
**Answer:** d) Both a and c
10. Given the declaration: `int[][] matrix = new int[3][3];`, what will `[Link]` return?
a) 3
b) 9
c) Contains 3 subarrays of size 3
d) Error
**Answer:** a) 3