Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

class B { private String name; public B(String s) { name = s; } public void fina

ID: 3714312 • Letter: C

Question

class B {

private String name;

public B(String s) {

name = s;

}

public void finalize() {

System.out.print(name);

}

}

10

class E {

public static void m() {

B x1 = new B("X"), y1 = new B("Y");

}

public static void main(String[] args) {

m();

System.gc();

}

}

If the above is stored in a file called E.java, which 2 of the following could be a result of attempting to compile and run the program?

Prints: XY

Prints: YX

Prints: XXYY

Nothing is printed.

None of the above

Compilation error

An exception is thrown

Explanation / Answer

Answer: Prints: YX

The output of the above code is Prints: YX