text: how to access the variables defined in one class by next class in java? (not through main())?   you can choose to make those variables public. that way, if you create objects of this class, you could reference these variables as object.variable  however, you are better off keeping the variables private and giving some kind of set and get methods that are declared as public and that let you get the values of the variables  eg: private int variable; public void setvariable(int x) {    variable = x; } public int getvariable() {    return variable; }  hope this helps!