Question: How to access the variables defined in one class by next class in java? (not through main())? 

Answer: you can choose to make those variables public.\nThat way, if you create objects of this class, you could reference these variables as object.variable\n\nHowever, 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\n\neg:\nprivate int variable;\npublic void setVariable(int x) {\n   variable = x;\n}\npublic int getVariable() {\n   return variable;\n}\n\nHope this helps!
This question from the Yahoo Q&A forum is categorized in the topic: Education & Reference