posted 11 years ago
When you pass a value of a primitive to a method and manipulate it inside the called method, the change is not reflected inside the calling method. This is because Java uses pass by value method.
If you want the incremented value in the calling mehod then you shound return the incremented value from the method called and store it in a variable inside the calling method(main, in your case) as below:
y will have a value 6.
and your method definition becomes:
Hope this helps..
Cheers!!!