The less obvious point to be made obvious in our discussion here is this.
All
Array elements of an array irrespective of whether the array has instance/class/local scope, always get initialized to their default values,
provided the array itself was constructed in the first place.
In other words,
still the concept of all member var gets initialized automatically and local vars NOT get initialized automatically holds good for vars of array type declaration also. for example take a class like this.
<pre>
class Test {
static int[] memArray;
static int[] memArray1 = new int[10];
public static void main(String[] args) {
int[] localArray;
int[] localArray1 = new int[10];
System.out.println(memArray); // prints null
//System.out.println(localArray); //COMPILE error
System.out.println(memArray1[0]); //prints 0
System.out.println(localArray1[0]); //prints 0
}
}
</pre>
If you look closely , in the above code the uninitialized array var
memArray gets initialized to null wheras
the local array localArray is NOT auto inited to null and compiler error occurs when you try to access this local array var.
The extra point to note in case of array vars is ,since they have an added attribute called
array elements, what happens to them ? It is just the fact that if and only if the array gets constructed in memory with new ***[size], the added attributes called 'array elements' get initialized to their defaults irrespective of whether the array has local/instance/class level scope.
Do you all agree with the point what I am trying to say ?
Vivek,
Regarding your 2nd qstn, to a certain degree , yes taking mocks again and again reinforces the key concepts. In my opinion, you save them for the last 1 month. Before that you participate actively here. Then start taking the mocks from the easier to harder ones.
regds
maha anna
[This message has been edited by maha anna (edited June 04, 2000).]