Answer the question
In order to leave comments, you need to log in
How can I use one variable in different methods and classes?
public class Test {
public static void main(String[] args) {
int a = 10;
}
public static void G() {
System.out.println(a);
}
}
Answer the question
In order to leave comments, you need to log in
Declare it as a class field.
public class Test {
private static int a;
public static void main(String[] args) {
int a = 10;
}
public static void G() {
System.out.println(a);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question