This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
How to make a Variable public?
Posted by Avin Sinanan on November 28, 2001 at 2:16 AM
Does anyone know how to make a variable public to all classes?
take for example the code>..
public static void main(String args)
JFrame frame = new JFrame("One");
String name1 ;
String name2 ;
public String method1()
name1= "Rick" ;
public String method2()
name2 = "Jenny";
does anyone know how to make classses Class1 and Class2 recognise
the Strings name1 and name2 without adding a variables to Class1 and Class2. IS there anyway to make variables golbally accessable.. so that it can be recognised anywehere within a program..even within other classes?
And please don't tell me to delcare String name1 and String name2 within Class1 and Class2 respectively. I really need for my variables to be declared within the public class.