0% found this document useful (0 votes)
7 views

Multiple Choice Question based on Arrays(Solution)

The document contains multiple-choice questions related to arrays in Java, covering topics such as declaration, initialization, accessing elements, and handling exceptions. Each question is followed by the correct answer, providing a comprehensive overview of array concepts in Java programming. The questions range from basic to intermediate levels, making it suitable for learners looking to test their knowledge of Java arrays.

Uploaded by

radhikadaksh1983
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Multiple Choice Question based on Arrays(Solution)

The document contains multiple-choice questions related to arrays in Java, covering topics such as declaration, initialization, accessing elements, and handling exceptions. Each question is followed by the correct answer, providing a comprehensive overview of array concepts in Java programming. The questions range from basic to intermediate levels, making it suitable for learners looking to test their knowledge of Java arrays.

Uploaded by

radhikadaksh1983
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Multiple Choice Question based on Arrays 9. How do you declare a two-dimensional array in Java?

1. What is the default value of an array of integers in a) int[][] arr = new int[3,3];
Java? b) int arr[][] = new int[3][3];
a) 0 c) int arr = new int[3][3];
b) null d) int arr = [3][3]new int;
c) Garbage value Answer: b) int arr[][] = new int[3][3];
d) Depends on JVM 10. What will be the output of the following Java code?
Answer: a) 0 int[] arr = {1, 2, 3, 4, 5};
2. What is the index range of an array with 10 elements System.out.println(arr[5]);
in Java? a) 5
a) 1 to 10 b) 0
b) 0 to 9 c) ArrayIndexOutOfBoundsException
c) 0 to 10 d) Compilation error
d) 1 to 9 Answer: c) ArrayIndexOutOfBoundsException
Answer: b) 0 to 9 11. What is the correct way to initialize a String array?
3. What happens if you try to access an array element a) String[] names = new String[]{"Alice", "Bob", "Charlie"};
with an invalid index? b) String names = {"Alice", "Bob", "Charlie"};
a) Compile-time error c) String names[] = "Alice", "Bob", "Charlie";
b) Runtime error d) String names = new String[3]{"Alice", "Bob", "Charlie"};
c) The program executes with a garbage value Answer: a) String[] names = new String[]{"Alice", "Bob",
d) None of the above "Charlie"};
Answer: b) Runtime error 12. What happens when you assign an array reference to
4. How do you declare a one-dimensional integer array another variable?
in Java? a) A copy of the array is created
a) int arr[] = new int[5]; b) Both variables point to the same array
b) int arr[5]; c) It results in a compilation error
c) int arr = new int[5]; d) The old reference is lost
d) array int arr = new int[5]; Answer: b) Both variables point to the same array
Answer: a) int arr[] = new int[5]; 13. Which of the following statements about arrays in
5. What will happen if an array is declared without Java is true?
initialization in Java? a) Arrays are dynamic in size
a) It will not compile b) Arrays can store multiple types of data
b) It will throw a runtime exception c) Arrays are objects in Java
c) It will compile but contain default values d) Arrays must always be initialized
d) None of the above Answer: c) Arrays are objects in Java
Answer: c) It will compile but contain default values 14. What will happen if you assign a value to an array
6. Which of the following correctly initializes an array? index that exceeds its size?
a) int arr[] = {1, 2, 3, 4}; a) The array will resize automatically
b) int arr = {1, 2, 3, 4}; b) The value will be added at the last index
c) int arr(4) = {1, 2, 3, 4}; c) An ArrayIndexOutOfBoundsException will be thrown
d) array arr[] = {1, 2, 3, 4}; d) The program will terminate normally
Answer: a) int arr[] = {1, 2, 3, 4}; Answer: c) An ArrayIndexOutOfBoundsException will be
7. How do you determine the length of an array arr in thrown
Java? 15. What will be the output of the following code?
a) arr.length() int[] arr = {1, 2, 3, 4, 5};
b) arr.size() System.out.println(arr.length);
c) arr.length a) 4
d) arr.count() b) 5
Answer: c) arr.length c) Compilation error
8. Which of the following is true about arrays in Java? d) Undefined behavior
a) Arrays can store only primitive types Answer: b) 5
b) The size of an array can be changed dynamically 16. What happens when an array is declared as final in
c) Arrays are stored in a contiguous memory location Java?
d) Arrays can only be one-dimensional a) The array cannot be modified
Answer: c) Arrays are stored in a contiguous memory b) The reference to the array cannot be changed
location
c) The size of the array becomes fixed 34. What happens if you pass an array to a method in
d) It results in a compilation error Java?
Answer: b) The reference to the array cannot be changed a) The array is copied and modified locally
17. What is the correct syntax for declaring an array of b) A reference to the original array is passed
double values? c) The method creates a new array
a) double arr[] = new double[5]; d) The method cannot accept an array
b) double arr = new double[5]; Answer: b) A reference to the original array is passed
c) double arr() = new double[5]; 35. What will be the output of the following code?
d) double[] arr = double[5]; public class Test
Answer: a) double arr[] = new double[5]; {
18. What is the output of the following Java code? public static void main()
int[] arr = new int[5]; {
System.out.println(arr[2]); int[] arr = {10, 20, 30, 40, 50};
a) 0 System.out.println(arr[2]);
b) null }
c) Garbage value }
d) Compilation error a) 10
Answer: a) 0 b) 20
29. What will happen if the following code is executed? c) 30
int[] arr = new int[-5]; d) 40
System.out.println(arr.length); Answer: c) 30
a) -5 36. What will be the output of the following code?
b) 0 public class Test
c) Compilation error {
d) NegativeArraySizeException public static void main()
Answer: d) NegativeArraySizeException {
30. What is the correct way to declare and initialize a int[] arr = new int[5];
multi-dimensional array? System.out.println(arr[1]);
a) int[][] arr = new int[3][]; }
b) int arr[][] = {{1,2,3}, {4,5,6}}; }
c) int[][] arr = {new int[3], new int[2]}; a) 0
d) All of the above b) null
Answer: d) All of the above c) Compilation error
31. What is the output of the following code? d) Garbage value
int[][] arr = new int[2][3]; Answer: a) 0
System.out.println(arr.length); 37. What will be the output of the following code?
a) 2 public class Test
b) 3 {
c) 5 public static void main() {
d) Compilation error int[] arr = {1, 2, 3, 4, 5};
Answer: a) 2 System.out.println(arr.length);
32. Which of the following is not a valid way to initialize }
an array? }
a) int[] arr = new int[5]; a) 4
b) int arr[] = {1, 2, 3, 4, 5}; b) 5
c) int arr[] = new int[5]{1, 2, 3, 4, 5}; c) 6
d) int arr[][] = new int[3][4]; d) Compilation error
Answer: c) int arr[] = new int[5]{1, 2, 3, 4, 5}; Answer: b) 5
33. What will be the output of the following code? 38. What will be the output of the following code?
int[] arr = {10, 20, 30, 40, 50}; public class Test
System.out.println(arr[arr.length - 1]); {
a) 40 public static void main()
b) 50 {
c) 10 int[] arr = new int[3];
d) Compilation error arr[0] = 5;
Answer: b) 50 arr[1] = 10;
arr[2] = arr[0] + arr[1]; public static void main()
System.out.println(arr[2]); {
} int[] arr = new int[5];
} System.out.println(arr);
a) 10 }
b) 15 }
c) 5 a) [0, 0, 0, 0, 0]
d) Compilation error b) 0x1b6d7b8a (some memory address)
Answer: b) 15 c) null
39. What will be the output of the following code? d) Compilation error
public class Test Answer: b) 0x1b6d7b8a (some memory address)
{ 43. What will be the output of the following code?
public static void main() public class Test
{ {
int[] arr = {10, 20, 30, 40, 50}; public static void main()
System.out.println(arr[arr.length - 1]); {
} int[] arr = {3, 6, 9};
} System.out.println(arr.length);
a) 40 }
b) 50 }
c) Compilation error a) 3
d) 10 b) 6
Answer: b) 50 c) 9
40. What will be the output of the following code? d) Compilation error
public class Test Answer: a) 3
{ 44. What will be the output of the following code?
public static void main() public class Test
{ {
int[] arr = {1, 2, 3, 4, 5}; public static void main()
System.out.println(arr[5]); {
} int[] arr = {1, 2, 3, 4, 5};
} for (int i = arr.length - 1; i >= 0; i--)
a) 5 {
b) 0 System.out.print(arr[i] + " ");
c) ArrayIndexOutOfBoundsException }
d) Compilation error }
Answer: c) ArrayIndexOutOfBoundsException }
41. What will be the output of the following code? a) 1 2 3 4 5
public class Test b) 5 4 3 2 1
{ c) 54321
public static void main() d) Compilation error
{ Answer: b) 5 4 3 2 1
int[] arr = new int[5]; 45. What will be the output of the following code?
arr[0] = 10; public class Test
arr[4] = arr[0] * 2; {
System.out.println(arr[4]); public static void main()
} {
} int[] arr = {2, 4, 6, 8, 10};
a) 0 for (int i = 0; i < arr.length; i += 2)
b) 10 {
c) 20 System.out.print(arr[i] + " ");
d) Compilation error }
Answer: c) 20 }
42. What will be the output of the following code? }
public class Test a) 2 4 6 8 10
{ b) 2 6 10
c) 2 4 6 a) 10
d) Compilation error b) 8
Answer: b) 2 6 10 c) 12
46. What will be the output of the following code? d) None of the above
public class Test Answer: c) 10 (2 + 8)
{ 50. What will be the output of the following code?
public static void main() public class Test
{ {
int[] arr = {1, 2, 3, 4, 5}; public static void main()
System.out.println(arr[-1]); {
} int[] arr = new int[5];
} System.out.println(arr[arr.length]);
a) 5 }
b) 1 }
c) ArrayIndexOutOfBoundsException a) 0
d) Compilation error b) 5
Answer: c) ArrayIndexOutOfBoundsException c) ArrayIndexOutOfBoundsException
47. What will be the output of the following code? d) Compilation error
public class Test Answer: c) ArrayIndexOutOfBoundsException
{ 51. What will be the output of the following code?
public static void main() public class Test
{ {
int[] arr = {1, 2, 3}; public static void main()
arr = new int[]{4, 5, 6}; {
System.out.println(arr[0]); int[] arr = {1, 2, 3, 4, 5};
} arr = null;
} System.out.println(arr.length);
a) 1 }
b) 4 }
c) Compilation error a) 5
d) 0 b) 0
Answer: b) 4 c) NullPointerException
48. What will be the output of the following code? d) Compilation error
public class Test Answer: c) NullPointerException
{
public static void main() 52. What will be the output of the following code?
{ public class Test
char[] arr = {'A', 'B', 'C'}; {
System.out.println(arr); public static void main()
} {
} int[] arr = {10, 20, 30, 40, 50};
a) A B C System.out.println(arr[0] + arr[2] + arr[4]);
b) ABC }
c) [A, B, C] }
d) Compilation error a) 60
Answer: b) ABC b) 100
49. What will be the output of the following code? c) 80
public class Test d) 120
{ Answer: d) 90 (10 + 30 + 50)
public static void main() 53. What will be the output of the following code?
{ public class Test
int[] arr = {2, 4, 6, 8}; {
System.out.println(arr[0] + arr[arr.length - 1]); public static void main()
} {
} char[] arr = {'A', 'B', 'C', 'D'};
System.out.println(arr[1] + arr[2]);
} int result = 1;
} for (int i = 0; i < arr.length; i += 2)
a) BC {
b) 131 result *= arr[i];
c) B C }
d) Compilation error System.out.println(result);
Answer: b) 131 (ASCII values: 'B' = 66, 'C' = 67 → 66 + 67 = }
131) }
54. What will be the output of the following code? a) 5000
public class Test b) 15000
{ c) 20000
public static void main() d) 6000
{ Answer: d) 6000 (10 * 30 * 50)
int[] arr = {5, 10, 15, 20}; 58. What will be the output of the following code?
System.out.println(arr[2] * arr[1]); public class Test
} {
} public static void main()
a) 150 {
b) 200 int[] arr = {10, 20, 30};
c) 100 arr = new int[5];
d) Compilation error System.out.println(arr[2]);
Answer: a) 150 (15 * 10) }
55. What will be the output of the following code? }
public class Test a) 10
{ b) 0
public static void main() c) 30
{ d) Compilation error
String[] arr = {"Hello", "Java", "World"}; Answer: b) 0 (Reassigning arr to a new array with default
System.out.println(arr[0] + " " + arr[arr.length - 1]); values)
} 59. What will be the output of the following code?
} public class Test
a) Hello Java {
b) Hello World public static void main()
c) Java World {
d) Compilation error int[] arr = {1, 2, 3, 4, 5};
Answer: b) Hello World for (int i = arr.length - 1; i >= 0; i--)
56. What will be the output of the following code? {
public class Test System.out.print(arr[i] + " ");
{ }
public static void main() }
{ }
int[] arr = {1, 2, 3, 4, 5}; a) 1 2 3 4 5
System.out.println(arr[arr.length / 2]); b) 5 4 3 2 1
} c) 54321
} d) Compilation error
a) 2 Answer: b) 5 4 3 2 1
b) 3 60. What will be the output of the following code?
c) 4 public class Test
d) 5 {
Answer: b) 3 (Middle element of the array at index 2) public static void main()
57. What will be the output of the following code? {
public class Test char[] arr = {'H', 'E', 'L', 'L', 'O'};
{ System.out.println(arr);
public static void main() }
{ }
int[] arr = {10, 20, 30, 40, 50};
a) HELLO public class Test
b) [H, E, L, L, O] {
c) H E L L O public static void main()
d) Compilation error {
Answer: a) HELLO (Character arrays print as a string in int[] arr = {1, 2, 3, 4, 5};
Java) System.out.println(arr[arr.length - 1]);
61. What will be the output of the following code? }
public class Test }
{ a) 5
public static void main() b) 4
{ c) 1
int[] arr = {10, 20, 30}; d) Compilation error
int[] arr2 = arr; Answer: a) 5 (Last element of the array)
arr2[1] = 50; 65. What will be the output of the following code?
System.out.println(arr[1]); public class Test
} {
} public static void main()
a) 20 {
b) 50 char[] arr = {'A', 'B', 'C'};
c) Compilation error System.out.println(arr);
d) 0 }
Answer: b) 50 (Both references point to the same array) }
62. What will be the output of the following code? a) A B C
public class Test b) [A, B, C]
{ c) ABC
public static void main() d) Compilation error
{ Answer: c) ABC (Character arrays print as a string in Java)
int[] arr = {2, 4, 6, 8}; 66. What will be the output of the following code?
System.out.println(arr[1] + arr[arr.length - 2]); int[] arr = {5, 8, 12, 3, 7};
} System.out.println(Math.max(arr[0], arr[3]));
} a) 3
a) 10 b) 5
b) 12 c) 7
c) 8 d) 8
d) 14 Answer: b) 5
Answer: b) 12 (arr[1] = 4, arr[2] = 6, so 4 + 6 = 12) 67. What does the following code print?
63. What will be the output of the following code? int[] arr = {4, -2, 7, -9, 0};
public class Test System.out.println(Math.abs(arr[3]));
{ a) -9
public static void main() b) 9
{ c) -7
int[] arr = {1, 3, 5, 7, 9}; d) 7
int result = 0; Answer: b) 9
for (int i = 0; i < arr.length; i += 2) 68. What will be the output of the following code?
{ int[] arr = {2, 6, 10};
result += arr[i]; System.out.println(Math.pow(arr[0], arr[1]));
} a) 36
System.out.println(result); b) 64
} c) 12
} d) 256
a) 25 Answer: b) 64
b) 12 69. What is the output of the following code?
c) 20 int[] arr = {16, 25, 36};
d) 15 System.out.println(Math.sqrt(arr[1]));
Answer: c) 15 (1 + 5 + 9 = 15) a) 4.0
64. What will be the output of the following code? b) 5.0
c) 6.0 c) 3.0
d) 25.0 d) 4.0
Answer: b) 5.0 Answer: a) 2.0
70. What is the result of executing this code? 77. What is the result of this Java snippet?
int[] arr = {1, 2, 3, 4, 5}; int[] arr = {4, 9, 16};
System.out.println(Math.min(arr[1], arr[3])); System.out.println(Math.sqrt(arr[arr.length - 1]));
a) 1 a) 2.0
b) 2 b) 3.0
c) 3 c) 4.0
d) 4 d) 9.0
Answer: b) 2 Answer: c) 4.0
71. What will the following code output? 78. What will be printed by the following code?
int[] arr = {-10, -5, -1}; int[] arr = {-3, -6, -9};
System.out.println(Math.abs(arr[2])); System.out.println(Math.abs(arr[1] + arr[2]));
a) -1 a) -15
b) 1 b) 0
c) -5 c) 15
d) 5 d) 6
Answer: b) 1 Answer: c) 15
72. What is the output of this Java snippet? 79. What will this Java snippet output?
int[] arr = {3, 9, 27}; int[] arr = {1, 5, 10};
System.out.println(Math.log(arr[2])); System.out.println(Math.pow(arr[0] + arr[1], arr[2] / 5));
a) 3.3 a) 6.0
b) 2.3 b) 36.0
c) 3.0 c) 10.0
d) 2.0 d) 60.0
Answer: c) 3.0 Answer: b) 36.0
73. What does this code print? 80. What is the output of the following Java code?
int[] arr = {4, 10, 20}; int[] arr = {3, 7, 15};
System.out.println(Math.ceil(arr[1] / 3.0)); System.out.println(Math.min(arr[0], Math.max(arr[1],
a) 3.3 arr[2])));
b) 4.0 a) 3
c) 3.0 b) 7
d) 10.0 c) 15
Answer: b) 4.0 d) 10
74. What will be the result of this Java code? Answer: a) 3
int[] arr = {2, 4, 8}; 81. What does this code print?
System.out.println(Math.random() * arr[2]); int[] arr = {10, 20, 30};
a) A random value between 0 and 2 System.out.println(Math.random() * arr[0] + arr[1]);
b) A random value between 0 and 4 a) A random value between 0 and 10
c) A random value between 0 and 8 b) A random value between 10 and 30
d) A random value between 2 and 8 c) A random value between 20 and 30
Answer: c) A random value between 0 and 8 d) A random value between 20 and 40
75. What does this code return? Answer: d) A random value between 20 and 40
int[] arr = {1, 2, 3, 4, 5}; 82. What will be the output of the following Java code?
System.out.println(Math.round(arr[2] / 2.5)); int[] arr = {2, 5, 8};
a) 0 System.out.println(Math.ceil(arr[1] / 2.0) +
b) 1 Math.floor(arr[2] / 3.0));
c) 2 a) 4.0
d) 3 b) 5.0
Answer: b) 1 c) 6.0
76. What will be the output of the following code? d) 7.0
int[] arr = {7, 14, 21}; Answer: b) 5.0
System.out.println(Math.floor(arr[1] / 5.0)); 83. What does this Java snippet return?
a) 2.0 int[] arr = {25, 49, 64};
b) 2.8 System.out.println(Math.sqrt(arr[0]) + Math.sqrt(arr[1]));
a) 10.0 int[] arr = {8, 10, 12};
b) 14.0 System.out.println(Math.sqrt(arr[2]) + Math.floor(arr[0] /
c) 15.0 3.0));
d) 18.0 a) 5.0
Answer: b) 14.0 b) 6.0
84. What will be printed by the following Java code? c) 7.0
int[] arr = {1, 2, 3, 4, 5}; d) 8.0
System.out.println(Math.round(arr[2] / 2.5 + arr[4] / 5.0)); Answer: b) 6.0
a) 1 91. What will this Java code print?
b) 2 int[] arr = {25, 100, 225};
c) 3 System.out.println(Math.sqrt(arr[1]) * Math.sqrt(arr[2]));
d) 4 a) 50.0
Answer: b) 2 b) 100.0
85. What is the result of executing this Java code? c) 150.0
int[] arr = {3, 6, 9, 12}; d) 200.0
System.out.println(Math.max(arr[1], Math.min(arr[2], Answer: b) 100.0
arr[3]))); 92. What does the following Java code return?
a) 6 int[] arr = {2, 4, 8};
b) 9 System.out.println(Math.floor(Math.random() * arr[2] +
c) 12 arr[1]));
d) 15 a) A random value between 2 and 8
Answer: b) 9 b) A random value between 4 and 8
86. What will be the output of the following Java code? c) A random value between 4 and 12
int[] arr = {3, 9, 27}; d) A random value between 8 and 12
System.out.println(Math.log10(arr[2])); Answer: c) A random value between 4 and 12
a) 1.0 93. What will be the output of this Java snippet?
b) 1.3 int[] arr = {5, 15, 25};
c) 1.5 System.out.println(Math.min(arr[1], Math.max(arr[0],
d) 1.7 arr[2])));
Answer: c) 1.5 a) 5
87. What does this Java code output? b) 15
int[] arr = {2, 4, 6, 8}; c) 25
System.out.println(Math.pow(arr[0], arr[2] / 2)); d) 30
a) 4.0 Answer: b) 15
b) 8.0 94. What does this Java snippet print?
c) 16.0 int[] arr = {4, 9, 16, 25};
d) 64.0 System.out.println(Math.sqrt(arr[3]) - Math.sqrt(arr[1]));
Answer: c) 16.0 a) 1.0
88. What will be printed by the following Java snippet? b) 2.0
int[] arr = {-5, -10, -15}; c) 3.0
System.out.println(Math.abs(arr[1]) - Math.abs(arr[0])); d) 4.0
a) -5 Answer: c) 3.0
b) 5 95. What is the output of the following Java snippet?
c) 10 int[] arr = {10, 20, 30};
d) 15 System.out.println(Math.round(arr[2] / 7.0) +
Answer: b) 5 Math.ceil(arr[0] / 3.0));
89. What is the result of this Java code? a) 5.0
int[] arr = {3, 7, 15}; b) 6.0
System.out.println(Math.min(Math.max(arr[0], arr[1]), c) 7.0
arr[2])); d) 8.0
a) 3 Answer: d) 8.0
b) 7 96.Assertion (A): In Java, an array can store elements of
c) 15 different data types.
d) 10 Reason (R): Java is a statically typed language, and arrays
Answer: b) 7 require a fixed data type at the time of declaration.
90. What does the following Java snippet output?
a) Both A and R are true, and R is the correct explanation Reason (R): Java allows arrays to store both primitive and
of A. reference types.
b) Both A and R are true, but R is not the correct a) Both A and R are true, and R is the correct explanation
explanation of A. of A.
c) A is true, but R is false. b) Both A and R are true, but R is not the correct
d) A is false, but R is true. explanation of A.
Answer: d) A is false, but R is true. c) A is true, but R is false.
97.Assertion (A): The size of an array in Java is fixed once d) A is false, but R is true.
it is declared. Answer: b) Both A and R are true, but R is not the correct
Reason (R): Java arrays are stored in contiguous memory explanation of A.
locations, which prevents dynamic resizing. 102.Assertion (A): In Java, arrays are always passed by
a) Both A and R are true, and R is the correct explanation reference to methods.
of A. Reason (R): When an array is passed to a method, any
b) Both A and R are true, but R is not the correct modification inside the method affects the original array.
explanation of A. a) Both A and R are true, and R is the correct explanation
c) A is true, but R is false. of A.
d) A is false, but R is true. b) Both A and R are true, but R is not the correct
Answer: a) Both A and R are true, and R is the correct explanation of A.
explanation of A. c) A is true, but R is false.
98.Assertion (A): Java supports multidimensional arrays. d) A is false, but R is true.
Reason (R): In Java, a two-dimensional array is internally Answer: a) Both A and R are true, and R is the correct
represented as an array of arrays. explanation of A.
a) Both A and R are true, and R is the correct explanation 103.Assertion (A): In Java, an array can be declared
of A. without specifying its size.
b) Both A and R are true, but R is not the correct Reason (R): The size of an array can be dynamically
explanation of A. allocated during initialization using the new keyword.
c) A is true, but R is false. a) Both A and R are true, and R is the correct explanation
d) A is false, but R is true. of A.
Answer: a) Both A and R are true, and R is the correct b) Both A and R are true, but R is not the correct
explanation of A. explanation of A.
99.Assertion (A): Accessing an array index beyond its c) A is true, but R is false.
declared size will throw an exception in Java. d) A is false, but R is true.
Reason (R): Java performs automatic bounds checking for Answer: c) A is true, but R is false.
arrays at runtime. 104.Assertion (A): The elements of an integer array in
a) Both A and R are true, and R is the correct explanation Java are automatically initialized to 0.
of A. Reason (R): Java does not allow arrays to have
b) Both A and R are true, but R is not the correct uninitialized elements.
explanation of A. a) Both A and R are true, and R is the correct explanation
c) A is true, but R is false. of A.
d) A is false, but R is true. b) Both A and R are true, but R is not the correct
Answer: a) Both A and R are true, and R is the correct explanation of A.
explanation of A. c) A is true, but R is false.
100.Assertion (A): The default value of an uninitialized d) A is false, but R is true.
boolean array in Java is false. Answer: a) Both A and R are true, and R is the correct
Reason (R): Java automatically initializes array elements explanation of A.
to their default values when declared. 106.Assertion (A): The length property of an array returns
a) Both A and R are true, and R is the correct explanation the number of elements in the array.
of A. Reason (R): The length property is a method in Java that
b) Both A and R are true, but R is not the correct computes the size of an array at runtime.
explanation of A. a) Both A and R are true, and R is the correct explanation
c) A is true, but R is false. of A.
d) A is false, but R is true. b) Both A and R are true, but R is not the correct
Answer: a) Both A and R are true, and R is the correct explanation of A.
explanation of A. c) A is true, but R is false.
101.Assertion (A): Arrays in Java are reference types and d) A is false, but R is true.
not primitive types.
Answer: c) A is true, but R is false.
(length is a property, not a method.)
107.Assertion (A): In Java, a for-each loop can be used to
modify array elements.
Reason (R): The for-each loop provides direct access to
array elements, allowing modification.
a) Both A and R are true, and R is the correct explanation
of A.
b) Both A and R are true, but R is not the correct
explanation of A.
c) A is false, but R is true.
d) A is true, but R is false.
Answer: c) A is false, but R is true.
(The for-each loop provides access to array elements, but
modifications do not affect the original array.)
108.
Assertion (A): Arrays in Java can store null values when
declared as object arrays.
Reason (R): Primitive data type arrays in Java can also
store null values.
a) Both A and R are true, and R is the correct explanation
of A.
b) Both A and R are true, but R is not the correct
explanation of A.
c) A is true, but R is false.
d) A is false, but R is true.
Answer: c) A is true, but R is false.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy