Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help in understading the GC question from ExamLab. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help in understading the GC question from ExamLab." Watch "Help in understading the GC question from ExamLab." New topic
Author

Help in understading the GC question from ExamLab.

Erum Momin
Ranch Hand

Joined: Jun 10, 2009
Posts: 32
Hi All,
Can anybody please help me understanding the output of this program... It's a question from Devaka's ExamLab.... And i'm unable to understand how to get the answer... can anybody please explain it to me...



How many objects are eligible for GC after executing line-10.
1.public class Garb{
2. Garb g;
3. pulic Garb(Object g){
4. this.g = (Garb) g;
5. }
6. public static void main (String args[]){
7. Garb gb1 = new Garb(new Garb(new Garb(null)));
8. gb1.g.g = new Garb(new Garb(null));
9. Garb gb2 = new Garb(new Garb(new Garb(gb1)));
10. gb2.g = gb1.g;
11. System.gc();
12. }
13. }
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

ExamLab is very popular among these forums -- a quick search will probably yield that this question has been asked many times already (See search link above).

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Erum Momin
Ranch Hand

Joined: Jun 10, 2009
Posts: 32
I tried searching for it on the forum but couldn't find it.... can anybody please help me.... the answer is 3 objects are eligible for the GC.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Erum Momin wrote:I tried searching for it on the forum but couldn't find it.... can anybody please help me.... the answer is 3 objects are eligible for the GC.


What did you search for? I just did a search for "Garb", and got this very topic as the first hit. And got the following topic as the second hit....

http://www.coderanch.com/t/418035/Programmer-Certification-SCJP/certification/SC-Exam-Lab-GC

Henry
Erum Momin
Ranch Hand

Joined: Jun 10, 2009
Posts: 32
believe me i did search for it. I found this question in practice exam 2 as 23rd question and i was searching for it.... but i didn't find it...
Anyways thanks for help.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Erum Momin wrote:believe me i did search for it. I found this question in practice exam 2 as 23rd question and i was searching for it.... but i didn't find it...
Anyways thanks for help.


Here is the FAQ page on how to search the ranch...

http://faq.javaranch.com/java/SearchFirst

There are actually some tricks, including using google, in searching the ranch's content effectively.

Henry
Erum Momin
Ranch Hand

Joined: Jun 10, 2009
Posts: 32
Henry Wong wrote:
Erum Momin wrote:believe me i did search for it. I found this question in practice exam 2 as 23rd question and i was searching for it.... but i didn't find it...
Anyways thanks for help.


Here is the FAQ page on how to search the ranch...

http://faq.javaranch.com/java/SearchFirst

There are actually some tricks, including using google, in searching the ranch's content effectively.

Henry


Thanks Henry....... Actually i'm new to this forum. So, don't know many of things here.... I'm planning to take my SCJP next week... I just read the K&B book and solving the examLab.... but i'm very much disappointed with the scores i got in the last two practice tests.... while reading the book i just went concept wise so i hardly remember any of the return types of the methods or the arguments they take... but ExamLab is quiet helpful...even reviewing the answers are helpful in clearing the doubts... right now i got 34% in both the practice test......... Please Give me some tips ..how should i prepare to improve my score.
Thanks again Henry ! ! !
Faisal Ansari
Ranch Hand

Joined: Jun 23, 2009
Posts: 36
there is no short cut way to pass the SCJP exam....just going through the concepts wont help you.....its better you write code snippets to reinforce the concepts you have learned....that way you will retain the concepts for a long time....and solve as many mocks as you can....they really do help in clearing the doubts.....and dont get disheartened at your scores in the ExamLab....it is tough actually....just put in a bit of hard work and you will pass with flying colours.....best of luck!!!


SCJP 6
 
jQuery in Action, 2nd edition
 
subject: Help in understading the GC question from ExamLab.