This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
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.

Consider Paul's rocket mass heater.
subject: JQuest
Similar Threads
JQuest Cert Simulation Question
JQUEST question on GC
JQuest question
Gc from JQuest