MCQ

Java MCQ – Multiple Choice Questions and Answers – Array – Part 1

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.
 
 

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 ?

A char[] arr = new char();

B char[] arr = new char[6];

C char[] arr = new char(7);

D char[] 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?

A int [] arr = new int[10];

B int arr[] = new int[10];

C int arr[] = new int[10];

D int 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.
 

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?

A int arr [][] = {1, 2, 3};

B int [] arr = (1, 2, 3);

C int arr [] = {1, 2, 3};

D int [] 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 __________.

A sizeof(array)

B array.len

C array.length

D array.sizeof()

C
We can determine the length of an array using array.length.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *