Hi,
Given:
When I uncomment the block comment, I will see that every constructed object in
Dozens[] da is "null"!
In this question are 7 answers:
Which two are true about the objects created within
main(), and which are eligible for garbage collection when line 14 is reached?
A. Three objects are created
B. Four objects are created
C. Five objects are created
D. Zero objects are eligible for GC
E. One object is eligible for GC
F. Two objects are eligible for GC
G. Three objectsare eligible for GC
The right answer in this book is:
C and F are correct.
da refers to an object of type "
Dozens array", and each
Dozens object that is created comes with its own "
int array" object (but not when it's
null; my comment). When line 14 is reached, only the second
Dozens object (and its "
int array" object) are not reachable.
Answer F I can understand because two objects are eligible for GC: the second
Dozens object and the
int array object.
But why they see 5 objects that were created. I see only two da[0] and da[1] the others are null. When I write:
This three nulls that are created counts as objects?? When I read this article in Stackoverflow:
https://stackoverflow.com/questions/1894149/is-null-an-object it is absolutely no object?!
Is the answer wrong in this book?
Thanks for help.