This collection of Java Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Java Array”.
1. Array is a collection of ________.
A same type of elements
B different type of elements
C heterogeneous data
D Both A and C
A
An array is a collection of similar type of elements which has contiguous memory location.
2. In Java arrays are ________.
A objects
B object references
C primitive data type
D None of the above
A
In java an array is a container object that contains a fixed number of values of a single type. The size of an array is fixed when the array is created. After creation, its length is fixed.
3. We access data in Array using ________.
A Operator
B Variable
C Index
D Pointer
C
We access data in Array using index.
[st_adsense]
4. On the point of array initialization which is required to specify?
A Row
B Column
C Row and Column
D None of the above
A
Row is essential to specify when initializing an array. Example:
int[] arr = new int[20];
5. Which declaration is valid ?
Achar[] arr = new char();
Bchar[] arr = new char[6];
Cchar[] arr = new char(7);
Dchar[] arr = new char[];
B
Syntax for declaring an array in Java is:dataType[] arr = new dataType[Size];
As a result, option (A) and option (C) are wrong as parentheses ( ) is used in place of square brackets [ ].
Option (D) is wrong as the size of the array is missing.
6. Array can allocate __________.
A Static Memory
B Dynamic Memory
C Automatic
D None of the above
A
Arrays are static that can store a specific type of variables. Thus these arrays need to be initialized at the compile time.
7. Which is wrong declaration of array?
Aint [] arr = new int[10];
Bint arr[] = new int[10];
Cint arr[] = new int[10];
Dint arr[] = int [10] new;
D
int arr[] = int [10] new;is a wrong declaration because Operator new must be followed by array type and array size.
[st_adsense]
8. Index in array start with ______.
A -1
B 0
C 1
D null
B
Index in array start with 0.
9. Which is used to declare, create, and initlaize an array?
Aint arr [][] = {1, 2, 3};
Bint [] arr = (1, 2, 3);
Cint arr [] = {1, 2, 3};
Dint [] arr = {};
C
int arr [] = {1, 2, 3}; is used to declare, create, and initlaize an array, so Option A is incorrect because it initializes an int array with String literals. Option B is incorrect because it uses something other than curly braces for the initialization. Option C is incorrect because it provides initial values for only one dimension, despite the declared array is a two-dimensional array.
10. We can determine the length of an array using __________.
Asizeof(array)
Barray.len
Carray.length
Darray.sizeof()
C
We can determine the length of an array usingarray.length.
MCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More
[st_adsense]