Page 1 of 1

About Question enthuware.ocpjp.i.v11.2.919 :

Posted: Thu Jul 09, 2020 7:58 pm
by dimitrilc
Hello, I think all three options,

//4,
never in this method,
and Cannot be determined

are all correct answers since we don't know whether Object XXX is still being used by other parts of the code or not.

Or is it a fact that if an object is returned by a method, it can never be garbage collected?

Re: About Question enthuware.ocpjp.i.v11.2.919 :

Posted: Fri Jul 10, 2020 1:02 am
by admin
>>are all correct answers since we don't know whether Object XXX is still being used by other parts of the code or not.
The question is above the code given in the problem statement. You need to consider only what happens in that code.

>>Or is it a fact that if an object is returned by a method, it can never be garbage collected?
If an object is being returned by a method then it cannot be garbage collected in that method. If it is garbage collected in that method, how will it be returned to the caller?

Re: About Question enthuware.ocpjp.i.v11.2.919 :

Posted: Fri Jul 10, 2020 10:07 am
by dimitrilc
Hello, Aren't your two statements contradicting one another?

Here you said to not assume any code outside of this piece of code:
The question is above the code given in the problem statement. You need to consider only what happens in that code.

Here you said to assume the possibility of a caller outside of this piece of code:
If an object is being returned by a method then it cannot be garbage collected in that method. If it is garbage collected in that method, how will it be returned to the caller?
Also, the keyword in the question is after, so yes, I had to assume cases where another caller uses it or not.

Re: About Question enthuware.ocpjp.i.v11.2.919 :

Posted: Fri Jul 10, 2020 11:22 am
by admin
The problem statement shows just a method. So, obviously, there is got to be code in which this method exists. Between the two options, the "Cannot be determined." option cannot be correct because you know that it cannot be GCed in this method! Therefore, given that you have to select only 1 option, "Never in this method." is the better option.

I would suggest you to go with the most reasonable interpretation than wasting time splitting hair. You have to allow for a little bit of subjectivity and apply common sense. Otherwise, you may end up spending more time over-analyzing. But it is up you.