Question: Which scenarios can be the result of compiling and running the following program? Select the two correct answers. (a) The program may print AB. (b)

Which scenarios can be the result of compiling and running the following program?

public class MyString { private String str; MyString (String str) { this.str

Select the two correct answers.

(a) The program may print AB.

(b) The program may print BA.

(c) The program may print A.

(d) The program may print B.

(e) The program may not print anything.

public class MyString { private String str; MyString (String str) { this.str = str; } } public void finalize () throws Throwable { System.out.print (str); super. finalize (); } public void concat(String str2) { this.str.concat (str2); } public static void main (String[] args) { new MyString ("A").concat ("B"); System.gc (); }

Step by Step Solution

3.54 Rating (161 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

c and e It is not guaranteed if and when garbage collection will occur nor in which order ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming 8th Questions!