• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Errata on Simulators?

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can somebody explain the next?:

I have a mock exam simulator and I'm not pretty sure if this question is right answered:

-----------------------------------
Here is a method which creates a number of String objects in the course of printing a count down sequence. When the program reaches line 8, how many of the String objects created in line 5 are eligible for garbage collection?. Assume that the System.out is not keeping a reference.

public void countDown()
{
for(int i = 10; i>=0; i--)
{
String tmp = Integer.toString(i);//line 5
System.out.println(tmp);
}
System.out.println("Boom!");//line 8
}

I think the answer is 11.

But my simulator states the anwser is 10. It also states only the last String object created still has a reference.

I think once outside the loop there's no more references for "tmp".
[ August 26, 2006: Message edited by: Barry Gaunt ]
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This loop will run 11 times and will create 11 object in loop, so the answer given that there is right.
 
Javier Sanchez Cerrillo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So If my simulator states the answer is 10 it is wrong?
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic