The following code has taken from "OCA/OCP
JAVA SE 8 PROGRAMMER PRACTICE TEST" book Chapter 2 - Working with Java Data Types
Query: There are two possible answers
"48. Which of the following is not a possible output of this code, assuming it runs to completion?
A. play-
B. play-play-
C. play-play-clean-
D. play-play-clean-clean-"
on page 437
"48. A. Remember that garbage collection is not guaranteed to run on demand. If it doesn’t run at all, Option B would be output. If it runs at the requested point, Option C would be output.
If it runs right at the end of the main() method, Option D would be output. (which is wrong) Option A is the correct answer because play is definitely called twice. Note that you are unlikely to see all these scenarios if you run this code because we have not used enough memory for garbage collection to be worth running. However, you still need to be able to answer what could happen regardless of it being unlikely."
As per chapter 2 - Q.17 explanation on p.434 "The finalize() method may not be called, such as if your program crashes. However,
it is guaranteed to be called no more than once."So, There are not two following possible outputs of this code
A. play-
D. play-play-clean-clean