Hi Yosi,
I think you are right that some of the 9 objects created in line 1 might have been garbage collected before the loop ends.
But for the sake of the exam, I think the answer is indeed 9.
The
SCJP exam expects us to know when such objects are eligible for GC, not when they are actually garbage collected. The keyword here is
eligible.
So, I think the wording in Dan's exam is already correct, and the answer is 9.
Just my 2 cents.