Prints value "10" as assigned with value "10" in ChangeVal method.
but in below code same procedure is being done but it does not accepts the assignment in populateArray() function and
prints "0" for all indexes.
If we populate the array in Testing class's constructor then it prints all the values .why ?
That happens because you are creating different instances of class Testing.
You create one in line 36, in the main method. You call populateArray() on that one in line 37.
But in the printArray method, you are creating a new instance of class Testing, in line 14, and then you iterate over the array in that new instance. You didn't call populateArray() on the Testing object that you created in line 14, so you see that the array contains all zeroes.