0

Is there a way to user the Scanner class in ex. Test_Main.java and make lets say int number1 = scan.nextInt() and then have number1 be one be visible to all the classes and have it change in all of the other classes?

LJP1203
  • 115
  • 2
  • 11
  • 3
    possible duplicate of [Global variables in Java](http://stackoverflow.com/questions/4646577/global-variables-in-java) – DavidPostill Nov 23 '14 at 04:57

1 Answers1

0

You have to use "static" keyword to make the changes available in all other classes. Below is the sample.

public static int number1 = 1;

static makes the variable class level, so you have to use it using the class name. In your case you can use as follows:

Test_Main.number1
Jigar Mistry
  • 352
  • 2
  • 12