This a nothing to do with reassigning string2 to string1. The String created are String literals and String literals are not garbage collected but hold in the private String pool.
And even if the Strings were created dynamically (i.e. with the keyword new) there would be one String being garbage collected (
Test) because on the third line string1 looses the reference to it and thus "Test" would be available for garbage collection.
To sum up,
no objects are garbage collected
BUT
string1 is available for garbage collection
Anywaym the answer provided is wrong !
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for
Java 2 Platform