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

Quiz: Shallow and Deep Copy · Question 7 of 10

What does this print? (code)

What does this print?

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[][] seats = {{0, 0}, {0, 0}};
        int[][] copy = seats.clone();
        copy[1][0] = 7;
        copy[0] = new int[]{5, 5};
        System.out.println(Arrays.deepToString(seats));
    }
}
  1. A.[[5, 5], [7, 0]]
  2. B.[[0, 0], [0, 0]]
  3. C.[[5, 5], [0, 0]]
  4. D.[[0, 0], [7, 0]]
Answer & explanation

Correct answer: [[0, 0], [7, 0]]

copy[1] is the same row as seats[1], so 7 shows up; copy[0] = new array only re-points the clone's own slot.

Can you get the rest right without peeking?

Take the timed Quiz: Shallow and Deep Copy quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →