//author 满晨晨
//time 2009 4 29上午
public classs hello{
public static int year;
public static void setYear(int a) {
year = a;
}
}
这种情况下不对hello实例化也可以直接调用
hello.setYear(18)
public class hello{
public int year;
public void setYear(int a){
year=a;
}
}
static静态的
必须hello a=new hello();实例化
它和构造方法是完全一样的
public hello()
{}
public hello(){int a=1;}
或者
public hello(int a){year=a;}
a.setYear(18)和a.year=20;同义的
可是setYear可以再方法中限定year的值
如
public void setYear(int a){
if(a<0||a>300){reyurn;}
else
year=a;
}