• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JQuest

 
luk Hann
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a question from Jquest:
Here is a method which creates a number of String objects in the course of printing a count down sequence.
1. public void countDown() {
2. for( int i = 10 ; i >= 0 ; i-- ){
3. String tmp = Integer.toString( i );
4. System.out.println( tmp );
5. }
6. System.out.println("BOOM!");
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.
Please explain why the answer is 10, not 11. Thanks.
Luk
 
petfishlf
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The answer should be 11 in Java 2.But I also heard some experts said in Java1.1 the answer is 10 .But Now Sun has corrected the minor bug in Java 2.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic