Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 179

Given the code fragments:

And:

Which statement is true?

    Correct Answer: B

    A

Discussion
UAK94Option: B

B is correct. After line 11 -> 2 objects are eligible for GC. After line 12 -> 3 objects are eligible for GC.

akbiyikOption: B

Answer is B.

iSnoverOption: A

The correct answer is letter A, an object is eligible for the garbage collector when it is no longer being used, as after line 11 no object is being used, the 3 are elected for the garbage collector. Even though "s2" can still be accessed, then on line 11 its scope is over so it is also elected to the garbage collector.

ShaileshRajOption: B

3 objects are created and at the end only S2 is being referenced other S1 and S2 has no reference. So answer is 2 objets are eligibe for garbage collection

RAADEL3IMLAKOption: B

answer is B

carlosworkOption: B

Answer is B.

BelloMio

My previous answer is incorrect. Scrap that.

BelloMioOption: B

We have 3 Student objects initially. first is reachable by S1 Second is reachable by S2 Third is reachable by S3 When we either nullify the reference or reassign it, we make it unreachable. There are generally four ways to make an object eligible for garbage collection. https://www.geeksforgeeks.org/garbage-collection-java/ Nullifying the reference variable Re-assigning the reference variable An object created inside the method Island of Isolation We are in the reassignment S1 = S3, we just made the object that had reference variable of S1 unreachable S3 = S2, we just made the object that had reference variable of S3 unreachable S1 = S2, we just made the object that reference variable of S1 unreachable. This object was the same as above. So in total, we have 2 objects eligible for garbage collection.