LearnFrenzy
Sign in Take a free test

Arrays in Java · Exercise 1 of 4

Arrays in Java Java Arrays MCQ

  • 20 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on Java arrays: creation and default values, length, indexes, references and copies, the Arrays class, 2D and jagged arrays, and covariance. Pick an option to check your answer instantly.

Question 1 Easy

What is the index of the first element of a Java array?

A 1
B 0
C -1
D It depends on the type
Question page & discussion
Question 2 Easy

How do you get the number of elements in an array a?

A a.length()
B a.length
C a.size()
D length(a)
Question page & discussion
Question 3 Easy

What does new int[3] contain?

A Random values
B 0, 0, 0
C null, null, null
D Nothing until assigned
Question page & discussion
Question 4 Easy

What does new String[2] contain?

A "", ""
B null, null
C "null", "null"
D It does not compile
Question page & discussion
Question 5 Easy

What happens when a program reads a[a.length]?

A It returns 0
B ArrayIndexOutOfBoundsException at run time
C Compile error
D It returns the last element
Question page & discussion
Question 6 Easy

Can you add a sixth element to an array created with new int[5]?

A Yes, with add()
B No – the size is fixed; create a larger array or use ArrayList
C Yes, by assigning a[5]
D Only for String arrays
Question page & discussion
Question 7 Medium

After int[] b = a;, what is true?

A b is an independent copy
B a and b refer to the same array; changing b[0] changes a[0]
C b is empty
D It does not compile
Question page & discussion
Question 8 Medium

What does new int[]{1, 2}.equals(new int[]{1, 2}) return?

A true
B false – arrays inherit Object.equals, which compares references
C Compile error
D It throws
Question page & discussion
Question 9 Easy

What does System.out.println(new int[]{1, 2, 3}) print?

A [1, 2, 3]
B Something like [I@6d06d69c – a type code and hash
C 1 2 3
D Compile error
Question page & discussion
Question 10 Easy

What must be true before calling Arrays.binarySearch(a, key)?

A a must contain key
B a must be sorted in ascending order
C a must be an int array
D a must have an even length
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links