必须在自己的文件中定义公共类型管理器

时间:2014-04-23 17:57:03

标签: java class drjava

我收到错误消息

Error: The public type Manager must be defined in its own file
Error: The public type Executive must be defined in its own file
Error: The public type EmployeeDemo must be defined in its own file

有没有一种简单的方法可以解决这个问题?

*
   A class to model an employee.
*/
public class Employee
{
   private String name;
   private double salary;

   /**
      Make an employee with a given name and salary.
      @param aName the name
      @param aSalary the salary
   */
   public Employee(String aName, double aSalary)
   {
      name = aName;
      salary = aSalary;
   }


   public String toString()
   {
      return "Name: " + name + " Salary: " + salary;
   }
}


public class Manager extends Employee

{
   private String department;


   public Manager(String name, double salary, String department)
   {
      super(name, salary);
      this.department = department;
   }

   public String toString()
   {
      return super.toString() + " Department: " + this.department;
   }
}

public class Executive extends Manager
{

   public Executive(String name, double salary, String department)
   {
      super(name, salary, department);
   }


   public String toString()
   {

      return super.toString();
   }
}


public class EmployeeDemo
{
   public static void main(String[] args)
   {
      Employee e1 = new Employee("Jeff", 30000);
      Employee e2 = new Manager("Larry", 80000, "Sales");
      Employee e3 = new Executive("Jayne", 80000000, "Regional VP");

      System.out.println(e1);
      System.out.println(e2);
      System.out.println(e3);
   }
}

1 个答案:

答案 0 :(得分:1)

为您的类创建新文件,您不能在同一文件中有多个公共类定义。

文件将以您的班级定义命名,因此public class Manager将被命名为Manager.java