我把它改成:Employee staff = new Employee("abc",2000,new Day(1989,10,1)); 还是有同样错误: No enclosing instance of type InitialValue is accessible. Must qualify the allocation with an enclosing instance of type InitialValue (e.g. x.new A() where x is an instance of InitialValue).我用的是j2sdk1.4.0;编辑器用的是eclipse。
如果要定义一个有3个Employee的数组,该如何写呢?
还是有同样错误:
No enclosing instance of type InitialValue is accessible. Must qualify the allocation with an enclosing instance of type InitialValue (e.g. x.new A() where x is an instance of InitialValue).我用的是j2sdk1.4.0;编辑器用的是eclipse。
还有个问题:要在main里面应用的话,涉及到的类全得加上 static关键字:
如: static class Employee
name=n;
salary=s;
hireDay=d;
}
Day 是什么呀
你想说的是Date吧!
要是Day,你又没有这样的构造方法,当然就不对了
Day是corejava包里的。
问题自己解决了,要写成:
InitialValue initval = new InitialValue();
Employee[] staff = new Employee[3];
staff[0]= initval.new Employee("abc",2000,new Day(1989,10,1));
staff[1]= initval.new Employee("cde",3000,new Day(1990,2,3));
staff[2]= initval.new Manager("def",4000,new Day(1999,3,22));
int i;
for(i=0;i<staff.length;i++) staff[i].raiseSalary(5);
for(i=0;i<staff.length;i++) staff[i].prt();一定要先有InitialValue的实例,而且要用这个实例去new?感觉好怪。
哪位大侠解释一下?
没有new InitialValue();
也就没有Employee.
把Employee定义为静态的
用new InitialValue.Employee()
看看把