• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unfair Question on JQ

 
Tarik Makota
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Never
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".
Tarik
 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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'
 
Tarik Makota
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should really then say Possibly Later isn't it rather than Never??
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3711
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, "Never in this method" should be good.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic