not sure -- but my guess is after line 7 i think seeing as there are 2 versions of str of which one hides the other. Therefore -- there are 2 references to the string "ABC". The 1st reference gets set to null al line 6 with str = null. The 2nd reference gets set to null with t.str = null. After this line there are now no more reference to "ABC".
after which line does the object created at line 1 is eligible for garbage collection and why
No object is created on line 1. str is an instance String reference variable and is part of the Test object created on line 2. The string literal "ABC" was already in the string literal pool when main() was called and it definitely cannot be garbage collected as long as class Test is reachable in memory.
One JavaRancher has asserted that the life of the string literal pool is associated with the life of the class loader. Since most programs use the jvm's class loader, that would mean that "ABC" will stay in memory until the jvm terminates. Since the gc is called by the jvm, that would mean that string literal "ABC" will never be garbage collected. [ March 24, 2005: Message edited by: Mike Gershman ]