aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes strings and gc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "strings and gc" Watch "strings and gc" New topic
Author

strings and gc

Sasikanth Malladi
Ranch Hand

Joined: Nov 04, 2000
Posts: 175
At what stage in the following method does the object initially referenced by s becomes available for garbage collection. Select the one correct answer.
void method X() {
String r = new String("abc");
String s = new String("abc");
r = r+1; //1
r = null; //2
s = s + r; //3
} //4


A.Before statement labeled 1
B.Before statement labeled 2
C.Before statement labeled 3
D.Before statement labeled 4
E.Never.
The answer is D. How?
(Question from the mock exam on javaprepare.
Thanks,
Shashi
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
s is a variable local to method(). When it is over s goes out of scope and is dead on the heap.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: strings and gc
 
Similar Threads
q on garbage collection
Garbage collection
garbage collection!!!
GC doubt
Garbage Collection