Calling Instance methods from main
Hello all,
I am learning java for the first time after finishing a course in windows application programming in C#.
I am starting with a simple program and i would like to know how i can call instance methods from within the main function (static).
Here is my code, i have not included all my source files since i believe they are not relevant to the question...
Every time i compile the following code i will get the error telling me that i cannot call the non-static method CreateEmployee() from a static reference.
Can anyone tell me how i would call this method from my main function?
Many Thanks,
Oli
package lab2;
import java.util.Scanner;
publicclass Lab2Testextends WeeklyEmployee
{
public Lab2Test(String employeeNumber,String name, String address,int age,int basicSalary,double hoursPerWeek, String firstClassKey)
{
super(employeeNumber, name, address, age, basicSalary, hoursPerWeek);
}
publicstaticvoid main(String args[])
{
int option;
Scanner in =new Scanner(System.in);
System.out.println("1: Create Employee");
System.out.println("2: Delete Employee");
System.out.println("3: Employee Gross Pay");
System.out.println("4: Employee Net Pay");
System.out.println("5: Employee Tax");
option = in.nextInt();
switch(option)
{
case 1:
CreateEmployee();
in.close();
break;
case 2://DeleteEmployee();
in.close();
break;
case 3://EmployeeGross();
in.close();
break;
case 4://EmployeeNet();
in.close();
break;
case 5://EmployeeTax();
in.close();
break;
default:;
}
}
publicvoid CreateEmployee()
{
System.out.println("Enter Employee Name: ");
}
/*
public void DeleteEmployee()
{
System.out.println("Delete Employee");
}
public void EmployeeGross()
{
System.out.println("Employee Gross Pay");
}
public void EmployeeNet()
{
System.out.println("Employee Net Pay");
}
public void EmployeeTax()
{
System.out.println("Employee Tax");
}*/
}
Message was edited by:
McPhee

