Page 1 of 1

Query on GC

Posted: Sat Jul 25, 2020 5:46 am
by amittora29
Hi,

I need help to understand below question and also the correct answer.

Class Student{
String name;
int age;
}

and other class :

public class test{
psvm(String [] args){
Student s1 = new Student();
Student s2 = new Student();
Student s3 = new Student();
s1=s3;
s3=s2;
s2=s1; // line 1

}

}

How many object are eligible for GC after line 1

Re: Query on GC

Posted: Sat Jul 25, 2020 5:54 am
by admin
You need to tell what do you think is the answer and why so that we can explain any issue with your reasoning.
Also, you need to quote the source from where you got this question.

Re: Query on GC

Posted: Sat Jul 25, 2020 7:29 am
by admin
You need to draw a diagram with references and objects. Then change the references after each statement.
Which book are you following?

Re: Query on GC

Posted: Sat Jul 25, 2020 8:35 am
by amittora29
Thanks for your reply. Does this looks ok. I am following kathy Sierra. Is there any other book you would recommend. pls see the diagram below ( attached)

Re: Query on GC

Posted: Sat Jul 25, 2020 8:58 am
by admin
No, like this:
test.jpg
test.jpg (84.15 KiB) Viewed 2616 times
Which book are you following?

Re: Query on GC

Posted: Sat Jul 25, 2020 9:12 am
by amittora29
Kathy Sierra. Is there any other book you would recommend. So what should be the answer. No objects available for GC after line 1

Re: Query on GC

Posted: Sat Jul 25, 2020 9:31 am
by admin
Answer is 1. There is no reference pointing to the first object at the end of line 1.
We recommend this:
https://www.amazon.com/gp/product/B07H6 ... nkCode=as2

Re: Query on GC

Posted: Sat Jul 25, 2020 1:45 pm
by amittora29
Thank you