If I have a function that in that function I declare:
Object arr[] = new Object[20];
Where are arr and the whole array stored? heap? stack? Does it matter if the declaration is in some function or in main()?
and let’s say I also have these command lines:
arr[0] = new String("abc"); arr[1] = new List();
where are arr[0]
and arr[1]
stored?
Advertisement
Answer
Memory diagram:
Boxes are memory locations (where binary numbers can be stored).
Arrows are memory references (i.e. pointers).