import javax.swing.*;
class Person {
public String name;
public static void main(String[] args) {
new Person().enter();
}
void enter(){
Person a = new Person();
String first = JOptionPane.showInputDialog(null,"Enter your first name");
a.name = first;
new la().a();
}
}
class la{
void a(){
Person a = new Person();
System.out.println(a.name);
}
}
As you can see what I'm trying to do here is to set global var 'name' from the JOption
input and to then be able to access 'name' with the new inputted var, from other classes later on. Since the workings of the classes later on depend on that var 'name'. Now I know I can simply pass these on through constructors to the relevant classes and avert this problem, but I want to know if this way is possible at all ?