static

public class Person {
//2
{
//代码块(匿名代码块)
System.out.println("匿名代码块");
}
//1 :只执行一次
static {
//静态代码块
System.out.println("静态代码块");
}
//3
public Person(){
System.out.println("构造方法");
}

public static void main(String[] args) {
Person person1 = new Person();
Person person2 = new Person();
}
}
//运行结果
静态代码块
匿名代码块
构造方法

posted @ 2021-07-26 19:21  清钦  阅读(41)  评论(0)    收藏  举报