Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 89

Given:

and

Which statement is true?

    Correct Answer: C

    In the `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.

Discussion
[Removed]Option: D

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.

ASPushkinOption: D

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

cathDevOption: A

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.

d7bb0b2Option: D

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.

d7bb0b2

Does not matter if jhon contain jane child, as this object no is used after the createPeople method is elligible for GC so D is correct

StavokOption: C

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