Manoj Kumar Jain wrote:This code will not compile, not because the array is uninitialized. Array elements are initialized with their default value that is 0 for integers.
This will fail because there is a local variable size that is not initialized before using and that is line no. 5
I know already that but i think elements arr- are also local variables.
The next question might be: well what value does it use? And that answer is also in the JLS (here). That second specification page also point to why size doesn't get a value: "A local variable must be explicitly given a value before it is used, by either initialization or assignment, in a way that can be verified."
I bring up the JLS - which may not be normal practice in the 'Beginning' forum because it is a great resource to search through when you have these types of questions.