0
How can i access variable from one method in another method from the same program?
5 ответов
+ 2
Atharv Kulkarni here, hope this helps
https://code.sololearn.com/c163DIPGI0x1/?ref=app
+ 4
That involves the concept of closure
In short, you need to either
Pass your variable as argument into the function being called
Or
Declare the variable in global scope
For further reading,
https://data-flair.training/blogs/java-closure/
+ 3
public class Program{
int i = 0;
public Program sum(int x, int y){
i=x+y;
return this;}
void getValue(int multi){
int total = i*multi;
System.out.print(total);}
public static void main(String[] args) {
Program obj = new Program();
obj.sum(5,5).getValue(2);}
}
+ 3
I think people are over complicating this for you, have you heard of the "return" statement?
+ 1
No i guess...
Will you help me