G
G. Burton
This is probably painfully obvious to a real programmer... Attempts at
compiling the following program result in the message:
Employee.java:9: non-static method
initEmployee(java.lang.String,float,boolean)
cannot be referenced from a static context
initEmployee(FRED, 6012f, true);
^
1 error
This is the entire source java file:
public class Employee
{
public static void main(String[] args)
{
// final indicates a constant.
final String FRED = "Fred";
Employee emp = new Employee();
initEmployee(FRED, 6012f, true);
String currentName = emp.displayEmpName();
System.out.println(currentName);
}
public void initEmployee(String employeeName_In, float sal_In,
boolean activeInd_In)
{ name = employeeName_In;
salary = sal_In;
active_Ind = activeInd_In;
System.out.println("Name: "+name);
System.out.println("Salary: "+salary);
System.out.println("Active Indicator: "+active_Ind);
System.out.println("Init Done");
}
public String displayEmpName()
{ return name; }
private String name;
private float salary;
private boolean active_Ind;
}
Any help to get a beginner going would be greatly appreciated.
Thanks in advance!
compiling the following program result in the message:
Employee.java:9: non-static method
initEmployee(java.lang.String,float,boolean)
cannot be referenced from a static context
initEmployee(FRED, 6012f, true);
^
1 error
This is the entire source java file:
public class Employee
{
public static void main(String[] args)
{
// final indicates a constant.
final String FRED = "Fred";
Employee emp = new Employee();
initEmployee(FRED, 6012f, true);
String currentName = emp.displayEmpName();
System.out.println(currentName);
}
public void initEmployee(String employeeName_In, float sal_In,
boolean activeInd_In)
{ name = employeeName_In;
salary = sal_In;
active_Ind = activeInd_In;
System.out.println("Name: "+name);
System.out.println("Salary: "+salary);
System.out.println("Active Indicator: "+active_Ind);
System.out.println("Init Done");
}
public String displayEmpName()
{ return name; }
private String name;
private float salary;
private boolean active_Ind;
}
Any help to get a beginner going would be greatly appreciated.
Thanks in advance!