编写Java程序时出现问题,求高手解答
新手入门java,编写继承程序时出现了错误
import java.util.Date;
import java.util.GregorianCalendar;
import com.lesson.Employee.Manager;
public class EmployeeTest
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Manager boss = new Manager("Wade", 8000, 1987, 12, 15);
boss.setBonus(500);
Employee[] staff = new Employee[3];
staff[0] = boss;
staff[1] = new Employee("James", 5000,1987, 11, 23);
staff[2] = new Employee("Kobe", 6000,1988, 10, 23);
for(Employee e : staff)
e.raiseSalary(5);
for(Employee e : staff)
System.out.println("name=" + e.getName() + ",salary=" + e.getSalary() + ",hireDay=" + e.getHireDay());
}
}
class Employee
{
private String name;
private double salary;
private Date hireDay;
public Employee(String n, double s, int year, int month, int day)
{
name = n;
salary = s;
GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
hireDay = calendar.getTime();
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public Date getHireDay()
{
return hireDay;
}
public void raiseSalary(double byPercent)
{
double raise = salary * byPercent / 100;
salary += raise;
}
class Manager extends Employee
{
private double bonus;
public Manager(String n, double s, int year, int month, int day)
{
super(n, s, year, month, day);
bonus = 0;
}
public double getSalary()
{
double baseSalary = super.getSalary();
return baseSalary + bonus;
}
public void setBonus(double b)
{
bonus = b;
}
}
}
它显示了这个错误:No enclosing instance of type Employee is accessible. Must qualify the allocation with an enclosing instance of type Employee (e.g. x.new A() where x is an instance of Employee).