gpt4 book ai didi

java - 静态错误: This class does not have a static void main method accepting String[].

转载 作者:太空宇宙 更新时间:2023-11-04 13:23:14 26 4
gpt4 key购买 nike

我的代码编译得很好,但是当我运行它时,它给了我错误:

`Static Error: This class does not have a static void main method accepting String[]`

这是我的代码:

class Employee{
private String name; //name reference field
private int idNumber; //integer variable holding employee's ID number
private String department; //holds the name of the employees department
private String position; //holds the name of the employee's position in the department
//the following is the first required constructor
//using the terms n,i,d, and p to assign values to the above fields
public Employee(String n, int i, String d, String p){
name=n;
idNumber=i;
department=d;
position=p;
}
//the following is a constructor that sets the fields blank to be filled in
public Employee(){
name="";
idNumber=0;
department="";
position="";
}
//writing appropriate accessor and mutator methods for all the fields
public void setName(String n){ name=n; }
public void setIdNumber(int i){ idNumber = i; }
public void setDepartment(String d){ department = d; }
public void setPosition(String p){ position = p; }
public String getName(){ return name; }
public int getIdNumber(){ return idNumber; }
public String getDepartment(){ return department; }
public String getPosition(){ return position; }
}
//new program creating employee objects
public class EmployeeInfo
{
public static void main(String[] args)
{
//create an Employee object
Employee employee1 = new Employee("Susan Meyers", 47899, "Accounting", "Vice President");
//test the accessor methods
System.out.println("***employee1***");
System.out.println("Name: " + employee1.getName());
System.out.println("ID number: " + employee1.getIdNumber());
System.out.println("Department: " + employee1.getDepartment());
System.out.println("Position: " + employee1.getPosition());
//create another Employee object
Employee employee2 = new Employee();
//test the mutator methods
employee2.setName("Mark Jones");
employee2.setIdNumber(39119);
employee2.setDepartment("IT");
employee2.setPosition("Programmer");
System.out.println("\n***employee2***");
System.out.println("Name: " + employee2.getName());
System.out.println("ID number: " + employee2.getIdNumber());
System.out.println("Department: " + employee2.getDepartment());
System.out.println("Position: " + employee2.getPosition());
//create another Employee object
Employee employee3 = new Employee();
//test the mutator methods
employee2.setName("Joy Rogers");
employee2.setIdNumber(81774);
employee2.setDepartment("Manufacturing");
employee2.setPosition("Engineer");
System.out.println("\n***employee3***");
System.out.println("Name: " + employee3.getName());
System.out.println("ID number: " + employee3.getIdNumber());
System.out.println("Department: " + employee3.getDepartment());
System.out.println("Position: " + employee3.getPosition());
}
}

我知道我需要在某处添加“public static void main(String[] args)”命令,但我不确定在哪里!感谢您提供的任何帮助!

最佳答案

您正在创建两个不同的类员工和员工信息我假设您正在尝试执行 Employee 类,其中编译器无法找到 Public static void main

关于java - 静态错误: This class does not have a static void main method accepting String[].,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32874229/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com