We know that array in java in object. and also object is initialize to null in Java.
Then why is that array are initialize to 0.
Array in Java Initialize
Hi Mohit,
when you just declare an integer array i.e.
int[] arr;
in the above statement arr is an integer array and compiler will assign a null value to it.
But when you intialize it with new keyword i.e.
int[] arr = new int[length];
the compiler will assign a continuous block of memory of size equal to lenght*4 bytes as one integer takes 4 bytes and in this every 4 byte block will store 0 by default.
Hi Mohit
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.