This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.