ARRAY ONE MARK QUESTIONS
1. What is the output of the following code?
int[] arr = {1, 2, 3, 4};
System.out.println(arr[1]);
a) 1
b) 2
c) 3
d) Compilation error
2. What is the default value of an int array element in Java?
a) 1
b) 0
c) null
d) garbage value
3. Arrays in Java are:
a) Objects
b) Primitive types
c) References
d) Both a and c
4. Which of the following methods is used to copy an array in Java?
a) System.copyOf()
b) Arrays.copyOf()
c) Array.copyOf()
d) Collections.copy()
Prepared by Mukesh
-2-
5. What is the output of this code?
int[] arr1 = {1, 2, 3};
int[] arr2 = {1, 2, 3};
System.out.println(arr1 == arr2);
a) true
b) false
c) Compilation error
d) Runtime error
6. What will be the output?
int[] a = new int[3];
System.out.println(a[0]);
a) 0
b) null
c) Compilation error
d) ArrayIndexOutOfBoundsException
7. Find the output:
int[] arr = {10, 20, 30};
for (int i = 0; i < arr.length; i++) {
arr[i] = arr[i] + 5;
}
System.out.println(Arrays.toString(arr));
a) [10, 20, 30]
b) [15, 25, 35]
c) [5, 15, 25]
d) Compilation error
Prepared by Mukesh
-3-
8. Find the output:
int[] arr = new int[5];
System.out.println(arr[2]);
a) 0
b) null
c) Error
d) Garbage value
9. Find the output:
int[] arr1 = {1, 2, 3};
int[] arr2 = {1, 2, 3};
System.out.println(arr1 == arr2);
a) true
b) false
c) Compilation error
d) Runtime exception
10. Find the output:
int[] arr = {1, 2, 3};
System.out.println(Arrays.toString(arr));
a) [1, 2, 3]
b) 1 2 3
c) Compilation error
d) Hashcode
Prepared by Mukesh
-4-
11. Find the output:
int[] arr = new int[] {1, 2, 3, 4};
System.out.println(arr.length);
a) 3
b) 4
c) 5
d) Compilation error
12. Find the output:
int[] a = {1, 2, 3};
int[] b = a;
b[0] = 10;
System.out.println(a[0]);
a) 1
b) 10
c) Error
d) Undefined
13. Find the output:
int[] arr = {10, 20, 30};
for (int i : arr) {
i = i + 5; }
System.out.println(Arrays.toString(arr));
a) [10, 20, 30]
b) [15, 25, 35]
c) Compilation error
d) [0, 0, 0]
Prepared by Mukesh
-5-
14. Find the output:
int[] arr = new int[0];
System.out.println(arr.length);
a) 0
b) Error
c) -1
d) null
15. Find the output:
int[] arr = null;
System.out.println(arr[0]);
a) 0
b) null
c) Runtime error
d) Compilation error
16. Find the output:
int[] a = {1, 2, 3};
System.out.println(a.getClass().getSimpleName());
a) int[]
b) intArray
c) int
d) Compilation error
Prepared by Mukesh
-6-
17. Find the output:
int[][] arr = new int[2][];
System.out.println(arr[0][0]);
a) 0
b) Compilation error
c) NullPointerException
d) ArrayIndexOutOfBoundsException
18. Which of these is the correct way to declare an array in Java?
a) int arr[] = new int();
b) int arr = new int[5];
c) int arr[] = new int[5];
d) array arr = new array[5];
19. Which class is immutable in Java?
a) String
b) StringBuffer
c) StringBuilder
d) None
20. Find the output:
int[] a = {1, 2, 3};
int[] b = a;
b[0] = 10;
System.out.println(a[0]);
a) 1
b) 10
c) Compilation error
d) NullPointerException
Prepared by Mukesh
-7-
21. What does Arrays.toString(new int[3]) print?
a) [null, null, null]
b) [0, 0, 0]
c) [ , , ]
d) Compilation error
22. Find the output:
int[] arr = null;
System.out.println(arr[0]);
a) 0
b) null
c) NullPointerException
d) Compilation error
23. Arrays in Java are:
a) Primitive types
b) Objects
c) Value types
d) None of the above
24. What happens if we access array[length]?
a) 0
b) Compilation error
c) get last value
d) ArrayIndexOutOfBoundsException
Prepared by Mukesh
-8-
25. Find the output:
int[] arr = {1, 2, 3};
for (int i : arr)
i = i + 10;
System.out.println(arr[0]);
a) 1
b) 11
c) Compilation error
d) 10
26. How to find array length?
a) arr.size()
b) arr.length
c) arr.length()
d) arr.size
27. Find the output:
int[] a = new int[3];
System.out.println(a);
a) [0, 0, 0]
b) Garbage value
c) Memory reference string
d) Compilation error.
Prepared by Mukesh
-9-
28. Can an array store different types?
a) Yes
b) Only objects
c) No
d) Only primitives
29. What happens with negative array size?
int[] a = new int[-5];
a) -5 size created
b) ArrayIndexOutOfBoundsException
c) NegativeArraySizeException
d) Compilation error
30. How to clone an array?
a) arr.copy()
b) arr.clone()
c) clone(arr)
d) copy(arr)
31. Return type of clone()?
a) int
b) Object
c) Same array type
d) void
Prepared by Mukesh
-10-
32. Method to compare array values?
a) arr1 == arr2
b) arr1.equals(arr2)
c) Arrays.equals(arr1, arr2)
d) arr1.compare(arr2)
33. Find the output:
int[][] arr = new int[2][];
System.out.println(arr[0][0]);
a) 0
b) Compilation error
c) ArrayIndexOutOfBoundsException
d) NullPointerException
34. Find the output:
int[] a = {1, 2, 3};
a = null;
System.out.println(a.length);
a) 3
b) Compilation error
c) NullPointerException
d) 0
Prepared by Mukesh
-11-
35. How to sort an array in ascending order?
a) Collections.sort(arr)
b) arr.sort()
c) Arrays.sort(arr)
d) arr.order()
36. Which of these is the correct way to declare and initialize a 2D array?
a) int arr[][] = new int[3][3];
b) int[][] arr = {{1,2}, {3,4}};
c) int arr[][] = new int[][]{{1,2},{3,4}};
d) All of the above
37. Time complexity of accessing array index?
a) O(n)
b) O(log n)
c) O(1)
d) O(n²)
38. Time complexity of linear search?
a) O(1)
b) O(log n)
c) O(n)
d) O(n²)
Prepared by Mukesh
-12-
39. Which allows dynamic resizing?
a) Arrays
b) ArrayList
c) Object
d) None of the above
40. What does Arrays.binarySearch() assume?
a) Array is linear
b) Array is unsorted
c) Array is sorted
d) Array has nulls
Prepared by Mukesh