In the following line of code, does the compiler allocate memory to store 10 objects of MyClass or 10 references?
MyClass[] arr= new MyClass[10];
In other words, do arrays store references alone or the objects themselves?
Also, is the behaviour different for primitive types?
It allocates space for the references. In case of primitive types it allocates space = array length * primitive type byte size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With