java static learning
/*static learning */
class one {
public int a = 5;
static { // 类加载时就运行代码码
System.out.println("static");
}
static {
// static int b=2; error
System.out.println("static");
}
public static void test(int c) {
// static int b = 2; error
}
{
// 每次对象实例化就执行代码块
}
public static void main(String[] args) {
{
int a = 2;
System.out.println(a);
}
// int a=6; 生命周期从此开始,只到 error
{
int a = 3;
System.out.println(a);
}
}
}