Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JQuest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JQuest" Watch "JQuest" New topic
Author

JQuest

luk Hann
Ranch Hand

Joined: Jan 29, 2001
Posts: 48
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

Joined: Mar 02, 2001
Posts: 7
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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JQuest