permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes garbage collection 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 "garbage collection" Watch "garbage collection" New topic
Author

garbage collection

maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 187
#3 At what point will the object created on line 8 be eligible for garbage collection?

1 public class RJMould{
2 StringBuffer sb;
3 public static void main(String argv[]){
4 RJMould rjm = new RJMould();
5 rjm.kansas();
6 }
7 public void kansas(){
8 sb = new StringBuffer("Manchester");
9 StringBuffer sb2 = sb;
10 StringBuffer sb3 = new StringBuffer("Chester");
11 sb=sb3;
12 sb3=null;
13 sb2=null;
14 }
15 }



1 Line 11
2 Line 9
3 Line 12
4 Line 13
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

12 ??


SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
What do you think the answer is?

Also, please QuoteYourSources.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

i think ans is 12.
because sb refers to sb3, so it means when sb3 eligible for gc then sb will be eligible for gc as well.
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
13?


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

oh yes it should be 13 Ankur...
maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 187
curve karve wrote:#3 At what point will the object created on line 8 be eligible for garbage collection?

1 public class RJMould{
2 StringBuffer sb;
3 public static void main(String argv[]){
4 RJMould rjm = new RJMould();
5 rjm.kansas();
6 }
7 public void kansas(){
8 sb = new StringBuffer("Manchester");
9 StringBuffer sb2 = sb;
10 StringBuffer sb3 = new StringBuffer("Chester");
11 sb=sb3;
12 sb3=null;
13 sb2=null;
14 }
15 }



1 Line 11
2 Line 9
3 Line 12
4 Line 13


Answer:
4

Explanation:
On line 9 the object created on line 8 has the reference sb2 pointed to it. Until something happens to make that reference unable to reach the object it will not be eligible for garbage collection...............

Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
good questions on gc...where are the questions from?
maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 187
I got encountered to one of SCJP free mock tests online..from there..i am getting screwed badly....
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
tomoro is my exam....you prepared me for gc
maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 187
how are you prep for exam???good luck
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
follow K&B...the king of kings
Phungsuk Wangdu
Ranch Hand

Joined: Nov 04, 2009
Posts: 114
good question answer 4 must be right
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: garbage collection