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?

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
c and e It is not guaranteed if and when garbage collection will occur nor in which order ... View full answer
Get step-by-step solutions from verified subject matter experts
