Java Programming Multiple Choice Questions - Array
This section focuses on the "Array" in Java programming. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements and other competitive examinations.
1. Java array is a collection of ________.
A. similar type of elements
B. different type of element
C. heterogeneous data
D. Both A and C
View Answer
Ans : A
Explanation: An array is a collection of similar type of elements which has contiguous memory location.
2. Array data access using _____.
A. Operator
B. Variable
C. index
D. Pointer
View Answer
Ans : C
Explanation: Array data access using index.
3. At time of array initialization which is necessary to specify?
A. Row
B. Column
C. Row and Column
D. None of the above
View Answer
Ans : A
Explanation: Row is necessary to specify at time of array initialization.
4. Java Array can allocate __________.
A. Dynamic Memory
B. Static Memory
C. Both A and B
D. None of the above
View Answer
Ans : B
Explanation: Arrays in java are static lists that can store a certain kind of variables. Therefore these arrays need to be initialized at the compile time.
5. Which of the following is an incorrect array declaration?
A. int [] arr = new int[5].
B. int arr[] = new int[5].
C. int arr[] = new int[5].
D. int arr[] = int [5] new
View Answer
Ans : D
Explanation: int arr[] = int [5] is an incorrect array declaration because Operator new must be succeeded by array type and array size.
6. Index in array start with ______.
A. -1
B. 0
C. 1
D. infinite
View Answer
Ans : B
Explanation: Index in array start with 0.
7. Which of the following is used to declare,construct, and initlaize an array?
A. int arr [] [] = {1, 2, 3, 4};
B. int [] arr = (1, 2, 3);
C. int [] arr = {};
D. int arr [] = {1, 2, 3};
View Answer
Ans : D
Explanation: int arr [] = {1, 2, 3}; is used to declare,construct, and initlaize an array becuase
Option A is wrong because it initializes an int array with String literals.
Option B is wrong because it uses something other than curly braces for the initialization.
Option C is wrong because it provides initial values for only one dimension, although the declared array is a two-dimensional array.
8. We can calculate the length of an array using ________.
A. sizeof(array)
B. array.len
C. array.length
D. array.sizeof()
View Answer
Ans : C
Explanation: We can calculate the length of an array using array.length.
9. Which of the following is advantage of java array?
A. Code Optimization
B. Random access
C. Size No-Limit
D. Both A and B
View Answer
Ans : A
Explanation: Code Optimization and Random access the following is advantage of java array.
10. In java, array elements are stored in ________ memory locations.
A. Random
B. Sequential
C. Sequential & Random
D. Binary search
View Answer
Ans : B
Explanation: Array elements are stored in contiguous memory. Linked List is stored in random memory locations.
Also check :
Discussion