Java 有很多麻烦;表达式的非法开始

Java 有很多麻烦;表达式的非法开始,java,netbeans,Java,Netbeans,我对计算机编程非常陌生——在不到6周前就开始了这门课程——目前我在Netbeans中非法启动表达式方面遇到了麻烦 整个代码如下所示,因为我甚至不知道从哪里开始: public class Employees { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logi

我对计算机编程非常陌生——在不到6周前就开始了这门课程——目前我在Netbeans中非法启动表达式方面遇到了麻烦

整个代码如下所示,因为我甚至不知道从哪里开始:

public class Employees {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        public class Employee

        //properties
        private String name;
        private String ID;
        private String salary;

        //constructor
        public Employee (String name, String address, String dob) {
            this.name = name;
            this.ID = ID;
            this.salary = salary;
        }

        //method to print details on employees
        public void printDetails() {
            System.out.println("Employee name: " +this.name);
            System.out.println("ID: "+ this.ID);
            System.out.println("Annual Salary: " + this.salary);
        }
    }
}

不能在方法声明public static void mainString[]args{中声明类public类Employee

最好将类Employee的声明移动到它自己的文件Employee.java中。如果不想将其移动到其他文件中,也可以将其移动到现有文件的末尾。但是必须将其声明为private而不是public

或者,您可以将所有内容设置为一个类,如下所示:

public class Employees {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Employees employee = new Employees("name", "address", "dob");
        employee.printDetails();
    }

    //properties
    private String name;
    private String ID;
    private String salary;

    //constructor
    public Employees (String name, String address, String dob) {
        this.name = name;
        this.ID = ID;
        this.salary = salary;
    }

    //method to print details on employees
    public void printDetails() {
        System.out.println("Employee name: " +this.name);
        System.out.println("ID: "+ this.ID);
        System.out.println("Annual Salary: " + this.salary);
    }
}

您可以在方法本地类的主体中声明一个类。但是人们很少这样做。@PaulBoddington是的……但是我们不要用一个可能根本不需要的特性来混淆初学者。