Originally posted by sonali rao:
When the code execution reaches at 'line y', total three String objects created at line x will be eligible for garbage collection.
Answer given: False
But i was thinking the answer should be true. Any inputs? Thanks in advance
I would be inclined to agree with you. 4 String objects are created, in total, but the last one will not have gone out of scope when you reach "line y." After "line y" is executed, 4 objects would be eligible for collection as the variable s would go out of scope when the method terminates. However, at "line y," only 3 String objects have gone out of scope and are eligible for collection. The fourth is still in scope.
Was there any reasoning behind this answer? I'd be interested to see what the author of the question had in mind.