← Quiz: Java Arrays: all 10 questions
Quiz: Java Arrays · Question 1 of 10
What does this print? (code)
What does this print?
public class Main {
public static void main(String[] args) {
int[] a = new int[4];
System.out.println(a[2] + a.length);
}
}
- A.2
- B.4
- C.6
- D.Error
Answer & explanation
Correct answer: 4
New int arrays are filled with 0, so a[2] + 4 = 4.
Can you get the rest right without peeking?
Take the timed Quiz: Java Arrays quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →