How many objects are eligible for garbage collection when the control reaches line 4 if the method process() is called with the argument of 5?
1. public void process(int count)
2. for ( int i = 1; i < count; i++ )
3. Object temp = " Hello "+i;
The ans for this is 0. But i feel it shld be 4 coz each time the loop is run the following strings will be created i.e Hello0,Hello1,Hello2,Hello3 which are distinct and will be eligible for garbage collection.
Can anyone clarify???