There is only one String object and that is "sample". anObj is just a reference pointing to "sample".
After line 7, both anObj and locObj point to "sample". After line 9, reference anObj points to null but locObj is still pointing to "sample" and thus "sample" is not eligible for GC.