You can also declare and construct an array in one statement as follows:

int[] testScores = new int[14];

This single statement produces the same result as the two previous statements.

Arrays of object types can be constructed in the same way:

Thread[] threads = new Thread[5];

The key point to remember here is that—despite how the code appears—the

Thread constructor is not being invoked. We’re not creating a Thread instance, but

rather a single Thread array object. After the preceding statements, there are still

no actual Thread objects!

Think carefully about how many objects are on the heap after a code statement

or block executes. The exam will expect you to know, for example, that the

preceding code produces just one object (the array assigned to the reference

variable named threads). The single object referenced by threads holds five

Thread reference variables, but no Thread objects have been created or assigned

to those references.

1 Answer

  • Anonymous
    1 decade ago
    Favorite Answer

    仔細想想,在執行完一小段的程式碼之後,究竟會產生多少 object。

    ( 這裡是指Thread[] threads = new Thread[5] )


    本次考試是希望你知道該段程式碼實際上只有產生一個 object,

    不過他是一個擁有 5 個 Thread refrence 陣列的 object,

    該 object 裡面的 5 個 Thread 並未被 new 出來。

    Source(s): myself
Still have questions? Get your answers by asking now.