WorksheetsArray - I
Total questions: 10
Worksheet time: 2mins
What is an array in Java?
A collection of different data types
A collection of similar data types stored in a single variable
A method to store data temporarily
A class used to store objects
Which of the following correctly declares and initializes an array?
int a = {1, 2, 3};
int[] a = new int{1, 2, 3};
int[] a = {1, 2, 3};
array a = [1, 2, 3];
What is the index of the first element in a Java array?
1
-1
0
Depends on array size
Which property is used to find the length of an array in Java?
length()
size()
length
count
Which statement is true about Java arrays?
Array size can change at runtime
Arrays store different data types
Array index starts from 1
Arrays have fixed size
Which loop is best suited to traverse an array using index?
while loop
if-else
for loop
do while
What is the default value stored in an int array?
null
1
0
garbage value
How many elements does the following array have?
int[] arr = {10, 20, 30, 40};
3
4
5
0
What will be the output of the following code?
int[] arr = {1, 2, 3}; System.out.print(arr[1]);
1
2
3
Error
What will be the output?
int[] a = new int[4];
System.out.print(a.length);
0
3
4
Error
