Hi, The object that becomes eligible for Garbarge collection is "Test", meaning only 1 in total object(s) are eligible for GC.
The other object "Today" is not eligible for GC because the String identifier string1 at line 4 is now pointing to it.
the flow is
1. string1 is pointing to "Test" 2. string2 is pointing to "Today" 3. string1 (set to null) therefore the connection to object "Test" is lost, then that object has no reference which makes it eligible for GC at that point. 4. string1 is given the address of string2 which points to "Today",
at that point you've got 2 identifiers (i.e. string1 and string2) pointing to the same object (i.e. "Today"), therefore there is still a reference to 1 object.