首页 新闻 会员 周边

入门菜鸟请教不兼容的类型问题

0
悬赏园豆:5 [已关闭问题] 关闭于 2013-06-10 09:44

import java.util.*;
public class ManagerTest
{
public static void main(String[] args)
{
Manager boss = new Manager("Tom",5000,1988,9,1);
boss.setBonus(6000);
Employee[] staff = new Employee[3];
staff[0] = boss;
staff[1] = new Employee("Jason",4000,1989,8,2);
staff[2] = new Employee("Kit",3000,1988,9,3);
for(Employee e : staff)
System.out.println("name = "+e.getName()+",salary = "+e.getSalary());
}
}
class Employee
{
public Employee(String n,double s,int year,int month,int day)
{
this.name = n;
this.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;
}
private String name;
private double salary;
private Date hireday;
}
class Manager extends Employee
{
public Manager(String n,double s,int year,int month,int day)
{
super(n,s,year,month,day);
bonus = 0;
}
public double getSalary()
{
double salary = super.getSalary();
return salary + bonus;
}
public void setBonus(double bon)
{
bonus = bon;
}
private double bonus;
}

编译之后在注释之处出现类型不兼容问题,可是getTime()返回的类型本就是Date类型,而我在实例域的声明之中也是声明的Date类型,类型是符合的,可是为什么编译之后会出现类型不兼容呢

问题补充:

在线等答案,急呀,希望有知道的告诉下谢谢

学海一浮萍的主页 学海一浮萍 | 菜鸟二级 | 园豆:202
提问于:2013-06-07 23:51
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册