Java OCA OCP Practice Question 204

Question

Given:

3. class Dozens {
4.   int[] dz = {1,2,3,4,5,6,7,8,9,10,11,12};
5. }//from w w  w  .  ja  va2 s . c o  m
6. public class Main {
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 which are eligible for garbage collection when line 14 is reached?

  • A. Three objects were created
  • B. Four objects were created
  • C. Five objects were created
  • D. Zero objects are eligible for GC
  • E. One object is eligible for GC
  • F. Two objects are eligible for GC
  • G. Three objects are eligible for GC


C and F are correct.

Note

da refers to an object of type "Dozens array" and each Dozens object that is created comes with its own "int array" object.

When line 14 is reached, only the second Dozens object and its " int array" object are not reachable.




PreviousNext

Related