Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ExamLab question???

 
jayalakshmi charugundla
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

After Line 12 , how many objects are eligible for garbage collection?
The answer is one object.

It is better to explain with the diagram and its really very helpful to me . Actually they told that we have to draw a small picture everytime whenever we see this type questions in the real exam too..

 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually they told that we have to draw a small picture everytime whenever we see this type questions in the real exam too

Who they?? You are not obliged to draw a diagram for these type of questions. If you can figure out the answer without any diagram, then you don't need to draw a diagram. If I have to create a diagram for this question, it would be like this
 
jayalakshmi charugundla
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Ankit, I couldn't understand the program even with this diafram. If you have time, could you explain this program from line 9 (A a1 =null;) to end?



 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets see this one line at a time

9. A a1=null;    A reference of class A is created an initialized to null.
10. A a2=new A(new A(null));   Here a2 points to an Object of class A. The class A has a field named a and the instance of class A which we pass to the constructor will be set to the field a. We can split this line to understand it better

11. A a3=new A(a2);    This one is also not that tough. a3 points to an instance of A and a3.a points to a2.

The rest of the statements should be easy to understand I think...
 
jayalakshmi charugundla
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so because of a2.a=null , one class obejct is eligible for gc. And the other object is referanced by a1 and a3. Am I right?

Why you have given two boxes for one object ? You could have given only one that is enough. thats why i didn't understand.

what actually the second box says? tell me by words
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so because of a2.a=null , one class obejct is eligible for gc. And the other object is referanced by a1 and a3. Am I right?

Yes that's right.
Why you have given two boxes for one object ?

Which two boxes??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic