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.