← Quiz: Java Methods: all 10 questions
Quiz: Java Methods · Question 3 of 10
What does this print? (code)
What does this print?
public class Main {
static void fill(int[] a) { a[0] = 42; }
public static void main(String[] args) {
int[] arr = new int[2];
fill(arr);
System.out.println(arr[0]);
}
}
- A.0
- B.42
- C.null
- D.Error
Answer & explanation
Correct answer: 42
The reference is copied, but both copies point to the same array, so its contents change.
Can you get the rest right without peeking?
Take the timed Quiz: Java Methods quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →