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);
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
Process completed.
转载于:https://blog.51cto.com/buzhidao/1309494