int array initialization

前端 未结 7 2128
暗喜
暗喜 2020-12-04 20:15

I have here a simple question related to Java. Let\'s say you have an int array as instance variable:

int[] in = new int[5];

So, now by def

7条回答
  •  青春惊慌失措
    2020-12-04 20:36

    It is the same thing if you do :

    int[] in = new int[5] as instance variable or local variable. The array object in will contain zeros in both cases.

    Difference would be if you would do something like :

    1. Instance variable : int[] in; (it is initialized with null), and the in object will live in heap space.

    2. Local variable : int[] in; (it has to be initialized by the user) will live in stack

提交回复
热议问题