Answer the question
In order to leave comments, you need to log in
How to change the variable created in the main method through another function?
How to change the variable created in the main method through another function? As I understand it, you can’t just take it into the argument of another function, since this will lead to the creation of a copy of the variable in the function, and not to change the value of this one. So how do you change a variable from another function?
Answer the question
In order to leave comments, you need to log in
First, local variables are local and other methods cannot access them. Declare variables as class fields.
Secondly, it is quite possible to pass a reference variable to another method as a parameter, without copying.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question