永发信息网

为什么这个程序老是说我 non-static variable this cannot be referenced from a static context

答案:2  悬赏:80  手机版
解决时间 2021-02-01 21:09
  • 提问者网友:抽煙菂渘情少年
  • 2021-01-31 21:54
package 课本例题;
import java.util.*;
public class employeetest {
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;
}
}
public static void main(String args[]){
employee staff[]=new employee[3];
staff[0] = new employee("张三",75000,1987,12,15);
staff[1] = new employee("李四",50000,1989,10,1) ;
staff[2] = new employee("王五",40000,1990,3,15) ;
for(int i=0;i staff[i].raisesalary(5);
for(int i=0;i employee e=staff[i];
System.out.println("姓名="+e.getname()+",工资="+e.getsalary()+",工作日期="+e.gethireday() );
}}}

package untitled3;
class zuobiao{
private float x;
private float y;
public zuobiao(float a,float b){
x=a;
y=b;
}
public float getx(){
return x;
}
public float gety(){
return y;
}
public static void main(String args[]){
zuobiao point[]=new zuobiao[4];
point[0] = new zuobiao(1,2);
point[1] = new zuobiao(1,3);
point[2] = new zuobiao(2,1);
point[3] = new zuobiao(3,2);
for (int i=0;i<4;i++){
zuobiao e=point[i];
System.out.println("x:"+e.getx()+"y:"+e.gety());
}
}}这个程序跟那个类似。.但这个就是对的
题目是课本上的程序.课本上好几个程序都是这样写的。但我打进到JBUILDER就会错.谁能详细的说说
最佳答案
  • 五星知识达人网友:廢物販賣機
  • 2021-01-31 23:33
自己好好去课本上看看。.你打错的。.
全部回答
  • 1楼网友:独行浪子会拥风
  • 2021-02-01 00:44
把person 类放到 demo4 之外
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯