public class A{
static int a=5;
public static void main(String args[]){
A testA=new A();
testA=null;
System.out.println(testA.a) }
}
问:输出是什么呢? 若是输出5,那么为什么??testA不是置空了吗,也可以调用static a 变量??哪位大侠解释下
static int a=5;
public static void main(String args[]){
A testA=new A();
testA=null;
System.out.println(testA.a) }
}
问:输出是什么呢? 若是输出5,那么为什么??testA不是置空了吗,也可以调用static a 变量??哪位大侠解释下
public class A{
static int a=5;
public static void main(String args[]){
A testA=new A();
testA=null;
System.out.println(A.a);//因为a是静态的,所以编译器自动忽略了你的变量而直接使用实际类替代}
}
static int a=5;
public static void main(String args[]){
A testA=null;System.out.println(testA.a) }
}结果还是5?不解
你没有实例化那testA只是个空得指针,这个指针只不过是A的类型。
因用A.a
而你新new出来的对象是指向另外的地址空间。