Java - MCQ
Multiple Choice Questions
Java MCQ - Methods and Arrays - Set 34
31. An array elements are always stored in ________ memory locations.
A). Sequential
B). Random
C). Sequential and Random
D). Binary search
View Answer
Correct: A
32. Which of these is an incorrect Statement?
A). It is necessary to use new operator to initialize an array.
B). Array can be initialized using comma separated expressions surrounded by curly braces.
C). Array can be initialized when they are declared.
D). None of the mentioned
View Answer
Correct: A
33. In Java arrays are
A). objects
B). object references
C). primitive data type
D). None of the above
View Answer
Correct: A
34. Which one of the following is a valid statement?
A). char[] c = new char();
B). char[] c = new char[5];
C). char[] c = new char(4);
D). char[] c = new char[];
View Answer
Correct: B
35. What is the result of compiling and running the following code?
public class Test{
public static void main(String[] args){
int[] a = new int[0];
System.out.print(a.length);
}
}
A). 0
B). Compilation error, arrays cannot be initialized to zero size.
C). Compilation error, it is a.length() not a.length
D). None of the above
View Answer
Correct: A