The answer is either 9 or 10 depending on how the version / venodr of your JVM chose to implement their variable handling mechanism.
The variable i goes out of scope when the for loop is complete. Some implementations may choose to destroy the i variable at that point, making the last object available for the gc.
However, in actuallity, while i goes out of scope and looses visibility to the program after the for loop, MOST vendors implement variable handling on a stack that is related to a "Frame" that corresponds to the method. Therefore the i would continue to exist until the method is over, even if YOU can't get to it. The gc would leave the object alone because SOMETHING still references it.
All that is why Bill was sorry that he put the darn question in the book worded that way. But feel free to harass him about it
. I believe that he just wrote ANOTHER book and is going to be doing a promotion and give away on that book shortly.
Yup, Just looked it up and William Brogden will be here NEXT WEEK!
His new book is "Java Developer's Guide to E-Commerce with XML and JSP" by Sybex.
I expect you will find him mostly hanging out in the XML forum.
[This message has been edited by Cindy Glass (edited June 16, 2001).]