Hi, I'm struggling a bit with a program I'm trying to write-- I keep getting the famous:
java:57: non-static variable this cannot be referenced from a static context
Newbie to Java-- I can't seem to figure out what's wrong:
import java.io.*;
import java.text.*;
// Name of Program.
class storm {
public class LK_Employee2 {
int num = 0;
// instance variable
void ask() {
// instance method
// Accept user input.
System.out.print("Please enter an Employee ID:");
// body of method
}
void get_disp() {
// instance method
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
String myString = br.readLine();
num = Integer.parseInt(myString);
// body of method
}
}
// Defines the start of a method called main.
public static void main (String args[]) throws Exception {
LK_Employee2 hazelnut= new LK_Employee2();
hazelnut.ask();
hazelnut.get_disp();
System.out.println("The Employee ID you entered was: " +hazelnut.num);
// Exit the program.
System.exit(0);
}
}
Thanks-
Lisa
UPS
java:57: non-static variable this cannot be referenced from a static context
Newbie to Java-- I can't seem to figure out what's wrong:
import java.io.*;
import java.text.*;
// Name of Program.
class storm {
public class LK_Employee2 {
int num = 0;
// instance variable
void ask() {
// instance method
// Accept user input.
System.out.print("Please enter an Employee ID:");
// body of method
}
void get_disp() {
// instance method
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
String myString = br.readLine();
num = Integer.parseInt(myString);
// body of method
}
}
// Defines the start of a method called main.
public static void main (String args[]) throws Exception {
LK_Employee2 hazelnut= new LK_Employee2();
hazelnut.ask();
hazelnut.get_disp();
System.out.println("The Employee ID you entered was: " +hazelnut.num);
// Exit the program.
System.exit(0);
}
}
Thanks-
Lisa
UPS