Loading

static关键字

static关键字

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

    public static void main(String[] args) {
            OOPDemo01 oopDemo01 = new OOPDemo01();
            System.out.println("==================");
            OOPDemo01 oopDemo011 =new OOPDemo01();
    }
}

输出:

静态代码块
匿名代码块
构造方法
==================
匿名代码块
构造方法
posted @ 2021-04-05 17:23  shumild  阅读(47)  评论(0)    收藏  举报