Suppose that we say:

Integer [] myarray = new Integer[1000];
for (int i = 0; i < 1000; i++)
   myarray[i] = new Integer(i);
About how many bytes are used by (a) the variable myarray, (b) what it points to, and (c) the total storage allocated by this code?

  • A: 8000, 8000 and 16000
  • B: 8, 8000 and 24000
  • C: 8, 8000 and 16000
  • D: 1000, 8000 and 9000
  • E: 1000, 8000 and 25000

    Answer: B

    The variable myarray is a reference variable, so it has the pointer size, 8 bytes.

    The array is an array of pointers, so it is about 8000 bytes.

    The pointers point to individual Integer objects, each of size 16 bytes, so these occupy 16000 bytes.

    Page-10    Prev    Next    Page+10