编译说不兼容的类型
找到:java.util.Date
需要:Date
             hireDay = c.getTime();
import java.util.*;
class Employee
{
private String name;
private double salary;
private Date hireDay;

public Employee(String name, double salary, int day, int month, int year)
{
this.name = name;
this.salary = salary;
GregorianCalendar c = new GregorianCalendar(year, month - 1, day);
hireDay = c.getTime();
}

public String getName()
{
return name;
}

public double getSalary()
{
return salary;
}

public Date getHireDay()
{
return hireDay;
}

public void raiseSalary(double byPersent)
{
double raise = salary * byPersent / 100;
salary += raise;
}
}class Maneger extends Employee
{
private double bonus;

public Maneger(String name, double salary, int day, int month, int year)
{
super(name, salary, day, month, year);
bonus = 0;
}

public double getSalary()
{
double baseSalary = super.getSalary();
return baseSalary + bonus;
}

public void setBonus(double bonus)
{
this.bonus = bonus;
}
}public class ManegerTest
{
public static void main(String[] args)
{
Maneger boss = new Maneger("a", 11, 1, 2, 3);
boss.setBonus(100);

Employee[] a = new Employee[3];
a[0] = boss;
a[1] = new Employee("b", 12, 2, 3, 4);
a[2] = new Employee("c", 13, 3, 4, 5);


for(Employee e : a)
{
System.out.println(e.getName() + " yours salary is " + e.getSalary() + " your hiretime is " + e.getHireDay());
}
}
}

解决方案 »

  1.   

    编译哪一行出错了?这个好像是《Java核心技术》上的代码
      

  2.   

    使用工具编译没有问题,是不是你的classpath没有配置好?
      

  3.   

    我用的是Myeclipse8.5,没有问题
      

  4.   

    代码是没有问题的 ,应该是配置JDK环境的问题吧
    F:\>javac ManegerTest.javaF:\>java ManegerTest
    a yours salary is 111.0 your hiretime is Thu Feb 01 00:00:00 CST 3
    b yours salary is 12.0 your hiretime is Sun Mar 02 00:00:00 CST 4
    c yours salary is 13.0 your hiretime is Fri Apr 03 00:00:00 CST 5F:\>