public class StaticTest {
private static int a;//默认分配的内存 并初始化 最初的数值
private static int b ;
private int k ;
/**
* @param args
*/
public static void main(String[] args) {
//int c ;
//System.out.println(c++);//非静态 没有初始化。会报错的
System.out.println(a);
testInt(a);
System.out.println(a);
System.out.println(b);
StaticTest ss = new StaticTest();
System.out.println(ss.k+2);//对象建立以后,就有默认值了
}
//原理 仍是值赋值的操做 将类变量a的值 赋值给 一个新的变量a 进行操做,此时的a 并非真实的类变量a.
//当时引用的 b 确实是 类变量b 。
public static void testInt(int a){
a = a+5;
b = b+1;
}
} c++
-------------------- spa
0 0 1 2 对象