class Member{
static int classVar;
int instanceVar;
static void setClassVar(int i){
classVar=i;
}
static int getClassVar(){
return classVar;
}
void setInstanceVar(int i){
classVar=i;
instanceVar=i;
}
int getInstanceVar(){
return instanceVar;
}
}
public class MemberTest{
public static void main(String args[]){
Member m1=new Member();
Member m2=new Member();
m1.setClassVar(1); //这里不是给ClassVar赋值1了吗!?可是为什么是打印出下面的2呢!?
m2.setClassVar(2);
System.out.println("m1.ClassVar="+m1.getClassVar()+" "+"m2.ClassVar="+m2.getClassVar());
m1.setInstanceVar(11);
m2.setInstanceVar(22);
System.out.println("m1.InstanceVar="+m1.getInstanceVar()+" "+"m2.InstanceVar="+m2.getInstanceVar());
}
}
打印结果:
m1.classVar=2 m2.classVar=2
m1.InstanceVar=11 m2.InstanceVar=22
麻烦看得懂的给我清楚地解释一下好吗!?
[求助]看不懂的程序!