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.
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.
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.
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.
Harid
Highly Voted 3 years, 11 months agoJongHwa
2 years, 8 months agohemassridhar
Highly Voted 4 years, 7 months agoyyfabc
Most Recent 1 year, 3 months agoRAADEL3IMLAK
1 year, 5 months agoakbiyik
1 year, 8 months agocarloswork
1 year, 9 months agoiSnover
1 year, 9 months agoludaka
5 months agoarcher1903
2 years, 1 month agobiggeek123
2 years, 7 months agobrianhuang881215
2 years, 11 months agobshailesh3
4 years, 5 months agokrkpnr
4 years, 5 months ago