Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 3 Of OCA/OCP Java SE 7 Programmer I & II Study Guide, need help on question 11

 
Joe McTigue
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am studying for the OCA Java SE 7 Programmer I cert test and was wondering if someone could explain question 11 in chapter 3 to me.
I understand what the answer is, the garbage collector finds only 1 object eligible for collection at line 16.
To better understand this I was wondering if one of you could tell me which object is eligible?

Here's the question:

Given:

When the above code reaches the "do stuff" comment, how many objects will be eligible for garbage collection?
A.) 0
B.) 1
C.) 2
D.) 3
E.) 4
F.) 5
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe McTigue wrote:To better understand this I was wondering if one of you could tell me which object is eligible?

I'm pretty sure this topic will answer every possible question you have about this question

Hope it helps!
Kind regards,
Roel
 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Still the answer will be 1?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin Tripathi wrote:Still the answer will be 1?

No, if you add a2 = null;, the answer will not be 1.
 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Are we noticing here a2.b2=b1,it will give answer 2,unlike this
 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And yeah Roel I noticed when
Then object of Alpha referenced by a2 will be available for GC
So 3 objects will be available for GC

Now Roel will you help by giving example,which is using some concept of Alpha.b1
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin Tripathi wrote:Then object of Alpha referenced by a2 will be available for GC
So 3 objects will be available for GC

Spot-on!

Sachin Tripathi wrote:Now Roel will you help by giving example,which is using some concept of Alpha.b1

I would (or at least could) if I knew/understood what you are looking for.
 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I was asking,about a code snippets which involves static reference variable like b1 in class Alpha

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin Tripathi wrote:Actually I was asking,about a code snippets which involves static reference variable like b1 in class Alpha

This code snippet has a static reference variable. So are you asking for other code snippets with static reference variables?
 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah!As I am not sure,I clearly understood the concept
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin Tripathi wrote:Yeah!As I am not sure,I clearly understood the concept

Unfortunately I am NotACodeMill. You should create a boatload of code snippets with static reference variables yourself (it's the best practice you can have) and if you encounter something where you are not sure about, just start a new topic and we will be glad to clear your doubts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic