public class Test
{
int i = 1;
public void run()
{
i++;
}
public static void main(String[] args)
{
Test t = new Test();
t.run();
System.out.println(t.i);// 值==2 没有问题
}
}
//如果这么写直接用对象调用 a的值怎么是1????????
public class Test
{
int a = 1;
public void run()
{
a++;
}
public static void main(String[] args)
{
new Test().run();
System.out.println(new Test().a);
}
}
|
|