File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Java 2 Study guide with Kathy Sierra, Self Test question 14, chapter 7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Java 2 Study guide with Kathy Sierra, Self Test question 14, chapter 7" Watch "Java 2 Study guide with Kathy Sierra, Self Test question 14, chapter 7" New topic
Author

Java 2 Study guide with Kathy Sierra, Self Test question 14, chapter 7

Shafkat Talli
Ranch Hand

Joined: Aug 01, 2003
Posts: 30
The question is about garbage collection. But as i c it, more than 2 answer can be given right (4 in my view).
IF I ANSWER (A) AND (B), THEN THE OBJECT I MAKE AT LINE 12 SHOULD BE ELIGIBLE FOR GARBAGE COLLECTION, DOESNT IT ?
-------------------------------------------------------------------
QUESTION 14) Given the following,
12. X3 x2 = new X3();
13. X3 x3 = new X3();
14. X3 x5 = x3;
15. x3 = x2;
16. X3 x4 = x3;
17. x2 = null;
18. // insert code
What two lines of code, inserted independently at line 18, will make an object eligible for garbage collection? (Choose two.)
A. x3 = null;
B. x4 = null;
C. x5 = null; <- right answer in the book
D. x3 = x4;
E. x5 = x4; <- right answer in the book


---------------------------<br />Shafkat Talli<br />SCJP 1.4, August 2003.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Welcome to the Ranch Snowman.
Please read our name policy and adjust your displayed name accordingly.
Either y=x; or y=null; will make the object pointed to by the variable y eligible for g.c. only if y is the sole variable that refers to that object. As long as there are some alias(*), none of the assignments will make the object eligible for g.c.
Note that at line 18 both x3 and x4 are pointing the same object --due to x4=x3;--. Thus neither A, nor B are valid answers. But at line 18 x5 is the unique reference to the second X3 object --created by X3 x3 = new X3();--, thus either C, or D will make that object eligible for g.c.
(*)more variables pointing to the same object.


SCJP2. Please Indent your code using UBB Code
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
I believe the keyword here is independently. If you answer A and B, then those 2 statements will be dependent on each other to make one object eligible for GC, i.e. you must put 2 statements at line 18, whereas the question is only asking for 1.
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
i agree with alton... you should only insert one line of code to make the object eligible for GC.


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8803
    
    5
The key word is 'independently'
We are not too happy about the grammer of that question, but we put it in there because you WILL see that kind of grammer on the exam. When you see a question like that it means:
There are X different answers (usually two or three), each answer only uses one line of code, you don't get to use more than one line of code to create a unique, single answer.
Does that help?
-Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Shafkat Talli
Ranch Hand

Joined: Aug 01, 2003
Posts: 30
ive changed my name now, and thanx ppl, i c it now !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java 2 Study guide with Kathy Sierra, Self Test question 14, chapter 7
 
Similar Threads
Garbage Collection
Garbage Collection
GC question
prob in grabage collector....?
a garbage collection question from K&B self-test