merely assign the finalvalue reference to the same array object referenced by the initial variable. It does not do an array copy. After the operation both variables will reference the same array object.
Since both are int array varables, the assignment is legal.
The key is that the variables "initial" and "finalvalue" are both of the same type: int array. They can reference any int array assigned (or re-assigned) to them.
The size of an array has to do with the object created -- not the variable it's assigned to.
Here, an int array is instantiated to length 3, and another int array instantiated to length 2. Initially, references to these objects are assigned to the variables "initial" and "final" value respectively. But there's no reason these can't be switched.
However, in your code, I think you'll find that both of these variables end up referencing the same object. Can you see why?
If you assign an array to a previously declared array reference, the array you're assigning must be the same dimension as the refrence you're assigning it to.
So I do not understand the above statement ? The code seems to work differently.
If you assign an array to a previously declared array reference, the array you're assigning must be the same dimension as the refrence you're assigning it to.
I think here the same dimension means with respect to 1-D, 2-D and so on. It does not refer to the size of the array as in your case the arrays are of size 2 and 3 respectively BUT the important thing to remember is that both have the same dimension.
I really hope that what I have said is right. If not, please correct me.