Return to site

JAVA CERTIFICATION QUESTION: Copying arrays in Java with the java.util.Arrays class

· java

When copying data, you need to know when you’ve copied a value contained in an object and when you’ve copied a reference to the object.

Given the class:

import java.util.Arrays;
public class Arr {
    public static void main(String[] args) {
        String[][] src = {{"A"},{"B", "C"},{"D", "E", "F"}};
        String[][] dest = Arrays.copyOf(src, 3); // line n1
        src[2][2]= "X"; // line n2
        System.out.print(src[2].equals(dest[2]));
    }
}

 

Which is the output? Choose one.

A. true

B. false

C. Runtime exception at line n1

D. Runtime exception at line n2

 

 

 

 

 

·Ɐ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ·uoᴉsnʅɔuoꓛ