File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Unfair Question on JQ 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 "Unfair Question on JQ" Watch "Unfair Question on JQ" New topic

Unfair Question on JQ

Tarik Makota

Joined: Jan 29, 2002
Posts: 23
Question ID :987945894790
After which line will the object created at line XXX be eligible for garbage collection?
public Object getObject(Object a) //0
Object b = new Object(); //XXX
Object c, d = new Object(); //1
c = b; //2
b = a = null; //3
return c; //4
Possible answers:
// 2
// 3
// 4
Can't Say
I answeres "Can't Say" and JQ says it is Never!!!
If looked in context of method they YES they are right but otherwise you can't say.
If JQ people reading it i think it should be worded better and 'Never' should not be option at all but:
"Not elegible for GC in getObject method".
mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
a method is called and then it executes and ends. that is the lifecycle of a method execution.
hence the question should be read in the context of the life cycle of the given method. And if you consider during the life time of the method, the object is not garbage collected as it gets returned when the method ends. (return c)
Rajinder Yadav
Ranch Hand

Joined: Jan 18, 2002
Posts: 178
Mark is right, a lot of people simply get confused when they come across this type of question for the first time and are presented with one of the possible asnwer being 'Never'
But if you do as Mark suggests you'll see the correct answer is 'Never'

<a href="" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes
Tarik Makota

Joined: Jan 29, 2002
Posts: 23
Yes i agree with you guys that in context of method answer is 'Never' but my point was that question like this one should be better worded.
Point of Mock is not to confuse people.
That was all.
Lionel Siau

Joined: Feb 27, 2002
Posts: 12
It should really then say Possibly Later isn't it rather than Never??
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3635
I think, "Never in this method" should be good.

Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
I agree. Here's the link:
subject: Unfair Question on JQ
It's not a secret anymore!