Originally posted by Manikandan Jayaraman:
Corey! Are you sure this is the reason? I feel to plainly reject choice 'a' as the answer because of the absence of a "," (comma) before BA. With a "Comma" in the beginning of choice 'a', it could have also been one of the answers. Any comments???
Obviously, the static variable ba references the object "Ba" from the time the class is loaded until the application completes. Therefore, finalize will
never be called on this object as it is
never eligible for garbage collection. The active reference, ba, prevents it from being so.
So, knowing that, we know that the only way we can get "Ba" to be in the output is to print it directly. If you look in the main method, we do print it, but it follows a comma. There is simply no way we could get "Ba" to come out of that application prior to the comma first being printed. Therefore, option A is incorrect.
In addition to that, if B2 were to be garbage collected after the System.out.println statement in main, the finalize method would have printed "B2" on a
second line because we used print
ln in main, which appends a carriage return. So, there's a second reason that option A is incorrect.
I hope that helps,
Corey