class A{
static int a = 0; //类变量
public int b = 0; //实力变量
}
public class Test{
public static void main (String[] args){
A a1 = new A();
A a2 = new A();
a1.a = 3; // 等同于 A.a = 3;
a1.b = 4 ;
System.out.println(a2.a); //结果为3
//类变量是针对所有对象的,所以a1改变a,a2的a也改变
System.out.println(a2.b); //结果为0
//实例只改变自身的,所以a1对象的b改变,不影响对象a2的b变量
}
}
class A{
static int a = 0; //类变量
public int b = 0; //实力变量
}
public class Test{
public static void main (String[] args){
A a1 = new A();
A a2 = new A();
a1.a = 3; // 等同于 A.a = 3;
a1.b = 4 ;
System.out.println(a2.a); //结果为3
//类变量是针对所有对象的,所以a1改变a,a2的a也改变
System.out.println(a2.b); //结果为0
//实例只改变自身的,所以a1对象的b改变,不影响对象a2的b变量
}
}