When does the string created on line 2 become eligible for garbage collection?
1. String s = "aaa"; 2. String t = new String(s); 3. t += "zzz"; 4. t = t.substring(0); 5. t = null;
A.
Line 3 creates a new string that contains aaazzz
and assigns t to point to that new string.
At that moment there are no references to the string created on line 2 ( "aaa"), so it becomes eligible for garbage collection.