Loading

Q1.

What will be the output of the following code?

int[] arr = {1, 2, 3, 4};

System.out.println(arr.length);

A. 3
B. 4
C. 5
D. Compilation error

Q2.

 Which of the following statements about arrays in Java is TRUE?

A. Arrays are objects in Java.

B. Array size can be changed after creation.

C. An array can store values of different data types.

D. Arrays are always passed by value in methods.

Q3.

What is the default value of elements in an int[] array in Java?

A. null
B. 0
C. garbage value
D. undefined

Q4.

Consider the following code:


int[][] arr = new int[2][];

arr[0] = new int[3];

arr[1] = new int[2];

System.out.println(arr[0].length + " " + arr[1].length);

What will be the output?

A. 2 3
B. 3 2
C. 5
D. Compilation error

Q5.

Which of the following is the correct way to copy an array in Java?

A. arr2 = arr1;
B. arr2.equals(arr1);
C. System.arraycopy(arr1, 0, arr2, 0, arr1.length);
D. arr2.clone(arr1);