I have a variable called “name” stored in another class in the working folder. I want to compare it to a user-input from a JOptionPane. The code I have is this:
String userInput = JOptionPane.showInputDialog(null, "What is the value?");
if(name.equals(userInput)){JOptionPane.showMessageDialog(null, "You are correct.");}
When I compile the program, it throws up the error that it cannot find symbol “name”. Do I have to call the variable some other way in order to compare it to the user-input or am I totally wrong here?
Lets say in working folder you have following two class:
So, that’s how you access a field of another class. if the field is
static, no need to create object usingnew; simply use the class name.