• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help in understading the GC question from ExamLab.

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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. }
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Erum Momin
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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....

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

Henry
 
Erum Momin
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ! ! !
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic