Balu Sadhasivam wrote:I guess thats because the static variable a[] is intialised before created
a[0]= 2 // tries to intialise the int array which is not yet created
int[] a // just declaration
It has be created using 'new' keyword = new int[5];
Technically, the variable a (an array variable) is never initialized in that code. You are attempting to assign a value to an element of a non-existent array object.