Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice TestPractice Test
About Exam
hard

2D Array Shallow Copy with Clone

Mark
< Prev
Next >

What is printed as a result of executing the following code segment?

public class ArrayCopy {
    public static void changeArray(int[][] arr) {
        int[][] copy = arr.clone();
        copy[0][0] = 100;
    }
    public static void main(String[] args) {
        int[][] data = { {1, 2}, {3, 4} };
        changeArray(data);
        System.out.println(data[0][0]);
    }
}
A

0, because the array elements are reinitialized to 0.

B

100, because arr.clone() creates a shallow copy that still shares inner arrays with the original.

C

1, because arr.clone() creates a deep copy, leaving the original array unchanged.

D

A compilation error occurs due to improper cloning of a 2D array.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|