Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ExamLab question??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "ExamLab question???" Watch "ExamLab question???" New topic
Author

ExamLab question???

jayalakshmi charugundla
Ranch Hand

Joined: Jul 22, 2009
Posts: 57
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

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


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
jayalakshmi charugundla
Ranch Hand

Joined: Jul 22, 2009
Posts: 57



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

Joined: Aug 03, 2008
Posts: 9291
    
  17

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

Joined: Jul 22, 2009
Posts: 57
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

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??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ExamLab question???
 
Similar Threads
Garbage collection
Garbage Collection
problem in gc
Question about Garbage collection from ExamLab diagnostic Test
Garbage Collector doubt (Examlab Diagnostic Test) Q4