菜鸟求救
我在做义个有关于继承的联系,但是编译器提示找不到符号,代码如下:import java. util.*;
public class ManagerTest{
public static void main(String[] args){
Manager boss=new Manager("carl",80000,1987,6,4);
boss.setBonus(50000);
Employee[] staff=new Employee[3];
Staff[0]=boss;
staff[1]=new Employee("jiangxudong",70000,1989,3,15);
staff[2]=new Employee("kok",60000,1990,5,4);
for (Employee e:staff)
System.out.println("name="+e.getName()+" salary="+e.getSalary()+" hireday="+e.gethireDay());
}
}
class Employee{
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 (Date)hireday.clone();
}
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 basesalary=super.getsalary();
return salary=basesalary+bouns;
}
public void setBonus(double b){
bonus=b;
}
private double bonus;
}
----------------解决方案--------------------------------------------------------
编译器找不到Manager和Employee
----------------解决方案--------------------------------------------------------
import java. util.*;
public class ManagerTest{
public static void main(String[] args){
Manager boss=new Manager("carl",80000,1987,6,4);
boss.setBonus(50000);
Employee[] staff=new Employee[3];
staff[0]=boss;
staff[1]=new Employee("jiangxudong",70000,1989,3,15);
staff[2]=new Employee("kok",60000,1990,5,4);
for (int i=0;i<3;i++)
System.out.println("name="+staff[i].getName()+" salary="+staff[i].getSalary()
+" hireday="+staff[i].gethireDay());
}
}
class Employee{
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 (Date)hireday.clone();
}
private String name;
public double salary;
private Date hireday;
}
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 salary=basesalary+bonus;
}
public void setBonus(double b){
bonus=b;
}
}
----------------解决方案--------------------------------------------------------
能运行了,还有点问题,就是没有计算雇佣日期,你自己改一下.我也有问题, for (Employee e:staff)
这是什么意思?
----------------解决方案--------------------------------------------------------
for (Employee e:staff)在这里就相当于for(int i=0;i<3;i++)
是JDK5.0新增加的一个循环结构:for (variable:collection)
类似于"for each"
----------------解决方案--------------------------------------------------------
我又重新写了个简化版的,去掉了hireday,其他的和上边一样,这回不提示找不到Employee了,但是Manager还是找不到,邪门了...
不就是一个自定义的类吗,怎么就找不到?
----------------解决方案--------------------------------------------------------
不会啊,我的都能运行啊.而且我用的比较老啊.
----------------解决方案--------------------------------------------------------
是啊,所以我说邪门了。重新COPY到另外一个地方,编译器也是说找不到Manager,但是不提示找不到Employee。。。。
----------------解决方案--------------------------------------------------------
你用记事本加控制台吧.有的时候可能是编译器的问题.你最好把错发出来给别人看看啊.再有问题我也不知道了
----------------解决方案--------------------------------------------------------
提示错误:
ManagerTest.java5:找不到符号
符号:类Manager
位置:类ManagerTest
Manager boss=new Manager("carl",80000,1987,6,4);
^
Manager boss=new Manager("carl",80000,1987,6,4);
^
.....
----------------解决方案--------------------------------------------------------