I think no of objects are 6
da is a array object
Under da, there are 3 Dozens objects
Line 9 an Line 10 creates one objects.
So, it totally creates 6 objects?
What do you think?
Given:
3. class Dozens {
4. int[] dz = {1,2,3,4,5,6,7,8,9,10,11,12};
5. }
6. public class Eggs {
7. public static void main(
String[] args) {
8. Dozens [] da = new Dozens[3];
9. da[0] = new Dozens();
10. Dozens d = new Dozens();
11. da[1] = d;
12. d = null;
13. da[1] = null;
14. // do stuff
15. }
16. }
Which two are true about the objects created within main(), and eligible for garbage collection when line 14 is reached?
Three objects were created
Four objects were created
Five objects were created
Zero objects are eligible for GC
One object is eligible for GC
Two objects are eligible for GC
Three objects are eligible for GC