W
W
WWH2017-10-18 20:42:35
Java
WWH, 2017-10-18 20:42:35

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

1 answer(s)
S
Sergey Gornostaev, 2017-10-18
@WWH

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 question

Ask a Question

731 491 924 answers to any question