【java】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 person = new Person();
        System.out.println("==============");
        Person person2 = new Person();
    }
}

 

posted @ 2022-04-10 16:18  hanyr  阅读(25)  评论(0)    收藏  举报