Hi all
I have this question from A Programmer's Guide to
SCJP Certification by Khalid Mughal et al Q# 9.12
What scenario can be the result of compiling and executing the following code -
Select the 2 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 print nothing
Their answer : c & e
My answer : a & e
Option e is definitely correct as the GC may not run at all.
However how the anonymous MyClass object is GCed before the concat() method is invoked is beyond me. Thus i think that option A is more plausible that option C
Also Option D is false since the anonymous
String object " World" invokes the finalize() method of String class and not of the MyClass class. Correct me if I am wrong.
Thanks