🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Arrays: all 10 questions

Quiz: Java Arrays · Question 8 of 10

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        int[] a = {1, 2, 3};
        int[] c = a.clone();
        c[1] = 50;
        System.out.println(a[1] + " " + c[1]);
    }
}
  1. A.2 50
  2. B.50 50
  3. C.2 2
  4. D.50 2
Answer & explanation

Correct answer: 2 50

clone() makes a separate copy, so changing c does not affect a.

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 →