When passing an object as an argument for a method, all changes that happen to the argument inside the method, affect the “original” object as well. That’s because the argument is a reference to the object.
But I also want to do the same with variables- I want all changes that happen inside the method to affect the “original” variable. But I don’t know how. I want to do this, because some times more than one local variables need to be processed in the same way.
How can I pass a reference to a variable as an argument for a method?
There is no other choice than to store the variable inside an object, and to pass the object. All arguments are passed by value in Java.
The object can be
this(i.e. the variable is in fact a field of the current object).