Hi All,
I came across this question in Exam Prep by Bill Brogden. Practice
test 1 question no.27.
____________________________________________________________
Here is a method which creates a number of
String objects in the course of printing a series of messages.
1: public void soundOff() {
2: for (int i=1;i<10;i++) {
3: String tmp = Integer.toString(i);
4: System.out.print(tmp + ", ");
5: }
6: System.out.println("10");
7: }
When the program reaches line 6, how many of the String objects created in line 3 are eligible for garbage collection? Assume that the System.out object is not keeping a reference.
a. none
b. 1
c. 8
d. 9
____________________________________________________________
The given answer is c.8,
but I think d.9 is correct. Could some one tell me the correct answer?
Thanks,
Malar.