Java MCQ – Multiple Choice Questions and Answers – Array – Part 2
This collection of Java Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Java Array”.
1. Which is the benefit of Java array?
A Size unlimited
B Random access
C Code Optimization
D None of the above
2. Array elements are stored in ________.
A Sequential memory
B Random memory
C Random & Sequential memory
D None of the above
3. What is the output of the following code?
public class Q3
{
public static void main(String[] args)
{
int[] arr = new int[0];
System.out.print(arr.length);
}
}
A Compilation error, the size of arrays can’t be initialized to zero.
B Compilation error, it’s arr.length() not arr.length
C 0
D None of the above
4. What is the output of the following code?
public class Q4
{
public static void main(String[] args)
{
int[] arr = {2, 3, 012 };
for(int i = 0; i < arr.length; i++)
System.out.print(arr[i] + " ");
}
}
A 2 3 12
B 2 3 012
C 2 3 10
D 2 3 null
5. Which keywords used to allocate memory to an array in Java?
A malloc
B allocate
C new
D construct
6. What is the output of the following code?
int a[] = new int[4]; System.out.print(a);
A Value stored in a[0]
B 0
C 00000
D Hexadecimal value
7. What is the output of the following code?
public class Q7
{
public static void main(String args[])
{
int arr[] = new int[10];
for (int i = 0; i < 10; ++i)
{
arr[i] = i;
System.out.print(arr[i] + " ");
i++;
}
}
}
A 0 2 4 6 8
B 1 3 5 7 9
C 0 1 2 3 4 5 6 7 8 9
D 1 2 3 4 5 6 7 8 9 10
8. When you give an array to a method, the method receives ___________ of the array.
A The reference
B The length
C The first element
D A copy
9. What is the output of the following code?
public class Q9
{
public static void main(String args[])
{
float[] arr = new float[]{1, 2, 3, 4};
System.out.println("Value is " + arr[1]);
}
}
A The program give a compile error due to the syntax new float[]{1, 2, 3, 4} is incorrect and it must be changed by {1, 2, 3, 4}.
B The code give a compile error due to the syntax new float[]{1, 2, 3, 4} is incorrect and it must be changed by new float[4]{1, 2, 3, 4};
C The code give a compile error due to the syntax new float[]{1, 2, 3, 4} is incorrect and it must be changed by new float[]{1.0, 2.0, 3.0, 4.0};
D The program compiles with no errors.
10. What is the output of the following code?
public class Q10
{
public static void main(String args[])
{
char arr [] = new char[5];
for (int i = 0; i < 5; ++i)
{
arr[i] = 'i';
System.out.print(arr[i] + "");
}
}
}
A 1 2 3 4 5
B 1 2 3 4
C i j k l m
D i i i i i



I’m extremely pleased to discover this website. I wanted to thank you for ones time just for this fantastic read!! I definitely enjoyed every part of it and i also have you bookmarked to see new stuff in your site.