
i need to access a variable from a class to another class currently running at the same time.
using Classname.variable i got the value. But when i change the value second time i got the previous value. I used static variabe.

Hi Friend,
Try the following code:
import java.util.*;
class A {
static int regd;
static int a;
public static int get() {
Scanner input=new Scanner(System.in);
System.out.print("Number:");
regd=input.nextInt();
a=regd;
return a;
}
}
public class B {
static int b=A.get();
public static void main(String[]args){
System.out.println(b);
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.