answer: D
A
Failed
createPerson() returns reference to Jack
next line is a line 2
B
Failed
createPeople() returns Jane
next line is a line1
C
Failed
createPerson() returns Jack with Jane as a parent
D
Correct
createPeople() returns Jane and reference to John is missed
At line 1, before the createPerson method is called, jane is referenced by person. After the method call, person references Jack, and jane is now the child of Jack. Since Jack is still referenced by person, its memory cannot be reused at this point.
However, if person were to be reassigned again to another object or set to null, the memory allocated for the Jack object could potentially be reclaimed by the GC, as there would be no more references to it, making it eligible for garbage collection and memory reuse.
D is correct. Because jhon no have more references in the code so is elegible for GC
C is not, because Jhon contain a reference to jane so cannot be elegible for GC and his memory cannot use in line 2.
Pretty sure the correct answer is D. Since the John Object is created and not returned by the createPerson() method. So John is ready to be garbage collected right after exiting the method.
createPeople() method, a Person object named jane is created and returned. This object is then passed to the createPerson() method, where a new Person object named Jack is created with jane as its child. The reference to the jane object is then overwritten by the reference to the new Jack object when it is returned from the createPerson() method and assigned to the person variable in the main() method. Since there are no more references to the jane object after this assignment, its memory can be reused by the garbage collector in line 2.
C is correct
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
7 months, 1 week agocathDev
9 months, 3 weeks agod7bb0b2
1 year agod7bb0b2
1 year ago[Removed]
1 year, 5 months agoStavok
1 year, 6 months ago