OK, the following is beyond the scope of the certification exam, so don't worry if this seems to nit-picky - you can safely ignore it if certification is your only goal.
The local variable tmp is out of scope by line 6, so the 11th object is
eligible for collection as well. This question has come up before, and I'm annoyed I can't find the previous topic where it came up, or I'd refer you there. The question is from Bill Brogden's book, right? He says the answer is 11, and elaborates on his reasoning
here. But Tony and I disagree with his reasoning. Our position is that even if a particular implementation of
Java holds on to the tmp reference after it's out of scope, so what? According to the language specs, Java
can discard tmp as soon as it's out of scope, and therefore the 11th object is
eligible for collection at that point even if a particular implementation will never successfully do so. Through
testing I've determined that jdk 1.2.2 for Windows can only collect 10 objects at line 6, but jdk 1.3 beta for Windows can collect all 11. I view this as a bug in 1.2.2 that has been fixed.
From an exam perspective also, I'd say the answer should be 11 simply because Brogden's argument for 10 (and my counterargument for 11) are outside the scope of what you're expected to know for the exam. The naive interpretation is that tmp is out of scope, so all 11 are eligible for collection. But that's just my opinion, of course.