Garbage Collection

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
RRRRRR
Posts: 26
Joined: Sun Jul 23, 2017 2:13 am
Contact:

Garbage Collection

Post by RRRRRR »

Sir my question is->

class Beta{}
class Alpha
{
static Beta b1;
Beta b2;
}

class Tester
{
public static void main(String[] args)
{
Beta b1=new Beta();
Beta b2=new Beta();
Alpha a1=new Alpha();
Alpha a1=new Alpha();

a1.b1=b1;
a1.b2=b1;
a2.b2=b2;

a1=null; b1=null; b2=null;

//doStuff
}
}

When line doStuff is reached there is only 1 Object eligible for Garbage Collection. Why???

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Garbage Collection

Post by admin »

What do you think and why?

RRRRRR
Posts: 26
Joined: Sun Jul 23, 2017 2:13 am
Contact:

Re: Garbage Collection

Post by RRRRRR »

Sir, Since I am reading from Kathy Sierra , Bert bates and it is written that there is still a reference to the object referred to by a2 , and there is still a reference to the object referred to by a2.b2 .

We can still access other Beta object through the static variable a2.b1 -> bcz its static //Can't understand this

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Garbage Collection

Post by admin »

Did you contact the authors of the book?
What did they say?

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests