Based on your earlier question, I think may not be fully digging the concept of the local variable. In this method:
public String setOption(String option) throws IOException
{
option = stdin.readLine();
return option;
}
option
is a local variable. You pass the initial value for that variable as an argument to the setOption
method each time you call it (and you happen to ignore that value), but with that detail out of the way, this is the same as
public String setOption() throws Exception
{
String option = stdin.readLine();
return option;
}
Now, local variables are something completely different from instance or class variables: they are valid only within a method body, and exist only during the time that method is executing. With that in mind, let's look at this code:
static BufferedReader stdin = new BufferedReader(new InputStreamReader(
System.in));
public static void main(String[] args) throws IOException
{
Patient.setOption(null);
}
Here you are basically misusing a class variable stdin
for something which should have been a local variable:
public static void main(String[] args) throws IOException
{
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
Patient.setOption(null);
}
On to the question of your method call... setOption
is currently an instance method, which means it must be called in the context of an instance. You are calling it as-is, with no instances of Patient
involved. If you continue down this road, you won't be able to represent more than a single patient, probably not your idea. So you want to keep the method as it is and create an instance of Patient
:
Patient p = new Patient();
p.setOption(...);
In your overall design it is not clear what role setOption
should play, but it is not a good idea that it uses the static stdin
variable (I already made it local above). You want to pass any data read from stdin
into the setOption
method and thus decouple it from the input reading logic.