Which goes on the stack or heap?

后端 未结 3 1065
北海茫月
北海茫月 2021-01-18 03:06

I am doing some studying and I came across a question that asks to show the correct memory diagram of the following code:

int [] d1 = new int[5];
d1[0] = 3;
         


        
3条回答
  •  [愿得一人]
    2021-01-18 03:41

    Arrays are not primitive in java it has concrete class in java.

    An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created.

    System.out.print(int[].class.toString());
    

    So when you create Object of any array type it must go to you heap space.

提交回复
热议问题