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 ]