如下面代码
Java代码
public class Test
{
public static int a = 2;
public static void main(String[] args)
{
Test t = new Test();
t = null;
System.out.println(t.a);
}
}
输出为:
2
下面的代码
Java代码
public class Test
{
public static int a = 2;
public int b = 3;
public static void main(String[] args)
{
Test t = new Test();
t = null;
System.out.println(t.a);
System.out.println(t.b);
}
}
输出为:
2
Exception in thread "main" java.lang.NullPointerException
再看下面的代码:
Java代码
public class Test
{
public int a = 3;
public static int b = 2;
public static void main(String[] args)
{
Test t = new Test();
t = null;
System.out.println(t.a);
System.out.println(t.b);
}
}
输出为:
Exception in thread "main" java.lang.NullPointerException