exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 121 discussion

Actual exam question from Oracle's 1z0-808
Question #: 121
Topic #: 1
[All 1z0-808 Questions]

Given the code fragments:

And:

Which statement is true?

  • A. After line 11, three objects are eligible for garbage collection.
  • B. After line 11, two objects are eligible for garbage collection.
  • C. After line 11, one object is eligible for garbage collection.
  • D. After line 11, none of the objects are eligible for garbage collection.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Harid
Highly Voted 3 years, 11 months ago
after line 11, nobody referencing to s1, thus makes s1 gc eligible. Even though s2 is null, it is not eligible for gc, because s3 still pointing to it. S3 is not eligible for gc because s1 is pointing to it. Only object that nobody pointing to is S1. After line 11 only one object is eligible for GC = S1.
upvoted 15 times
JongHwa
2 years, 8 months ago
No. s1, s2, s3 are just variable that has Object's reference value(=address value). they are not Object. you said "nobody referencing to s1". that's incorrect. -> "Nobody is referencing the object that s1 initially had." is correct.
upvoted 2 times
...
...
hemassridhar
Highly Voted 4 years, 7 months ago
Correct, object created at line num 6 will be eligible for GC.
upvoted 5 times
...
yyfabc
Most Recent 1 year, 3 months ago
tested, 2 objects are still referenced. public static void main(String[] args) { Object w1 = new Object(); Object w2 = new Object(); Object w3 = new Object(); w1 = w3; w3 = w2; w2 = null; System.out.println(w1); System.out.println(w2); System.out.println(w3); }
upvoted 1 times
...
RAADEL3IMLAK
1 year, 5 months ago
answer c is correct, tow objet is référenced
upvoted 1 times
...
akbiyik
1 year, 8 months ago
Selected Answer: C
Answer is C
upvoted 1 times
...
carloswork
1 year, 9 months ago
Selected Answer: C
For those who want an explanation, follow one from stackoverflow: https://stackoverflow.com/questions/68313719/java-object-garbage-collection
upvoted 1 times
...
iSnover
1 year, 9 months ago
Selected Answer: A
The correct answer is the letter A, the reason is that the 3 variables are local variables, so their scope is inside the main method, after line 11 it leaves the main method and the 3 variables lose their usability because they leave their scope , so all 3 are eligible to enter the Garbage collector.
upvoted 1 times
ludaka
5 months ago
Good point, but I think that your answer applies after line 12.
upvoted 1 times
...
...
archer1903
2 years, 1 month ago
Selected Answer: C
Answer is C
upvoted 1 times
...
biggeek123
2 years, 7 months ago
the answer is A after line 11 all are unreferenced
upvoted 1 times
...
brianhuang881215
2 years, 11 months ago
obviously,ans is C s2 in its heap area is null, so it is eligible for garbage collection
upvoted 2 times
...
bshailesh3
4 years, 5 months ago
Answer B is correct, as after assignment of null two references are still pointing. Tested.
upvoted 3 times
krkpnr
4 years, 5 months ago
and that means correct aswer is C.
upvoted 9 times
...
...
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.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago