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 Garbage Collection 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 "Garbage Collection" Watch "Garbage Collection" New topic
Author

Garbage Collection

Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

3. class Dozens {
4. int[] dz = {1,2,3,4,5,6,7,8,9,10,11,12};
5. }
6.
7. public class Eggs {
8. public static void main(String[] args) {
9. Dozens [] da = new Dozens[3];
10. da[0] = new Dozens();
11. Dozens d = new Dozens();
12. da[1] = d;
13. d = null;
14. da[1]= null;
15. // do stuff
16.
17. }
18.
19. }
20.

PLEASE READ CAREFULLY...THANKS

Question: How many objects are created within the "main() method",
and how many of those are eligible for garbage collection when line
14 is reached?¿?

Answer: five objects created and two objects eligible for garbage
collection. (REMEMBER "WITHIN THE MAIN METHOD").

The above answer would be correct if:
Dozens [] da refers to an object of type "Dozens array".

And if:
each newly created Dozen object has its own int array Object, meaning:
da[0] = new Dozens(); are two objects!!

1. Dozens Object.
2. int[] array Object

And, does this have anything to do with the "HAS-A" theory?¿?

I will be greatfull if anyone can clearify my doubts.


OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
Please use code tags to write codes. Thanks


SCJP 1.6 96%
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
Whatever you are saying is true. The explaination is perfect. Yes It is because of the Has-A relationship between Dozen and the int array.
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Neha Daga wrote:Please use code tags to write codes. Thanks

Thanks...I understand you and would appreciate better if after correcting
me "on quote tags", you end it up clearifying my doubts okay?¿? Thanks.
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
well I did that.
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Neha Daga wrote:well I did that.

Thanks body...
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Please => SearchFirst <= and => UseCodeTags <=. Discussed recently!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Ikpefua, there are a few guidelines that you should keep in mind while posting on javaranch. Using Code Tags is one of them. When you use code tags around your code, the code is easier to read. Also please mention the source when you post a mock exam question...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Thanks a lot for your information/advise, as you can see Im completely new in this game, such info would help me construct better posts in future. Thanks once again.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Garbage Collection
 
Similar Threads
Garbage Colection
Help with Garbage Collection
Garbage Collection - P274 Kathy Sierra
ch-assignment in kb ,need explanation of output:question 10
Question about GC and Objects