File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JQuest" Watch "JQuest" New topic


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.

Joined: Mar 02, 2001
Posts: 7
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:
subject: JQuest
It's not a secret anymore!