Java no name static method

后端 未结 2 1024
滥情空心
滥情空心 2021-02-01 17:41

What is this?

public class ABC {
   public ABC() {
         System.out.println(\"world\");
   }
   static {
         System.out.println(\"hello\");
   }
}
         


        
2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-01 18:19

    It's called a "static initialisation block".

    It runs when the class is first loaded; only once.

    For example, a constructor will run each time the class is instantiated; the static block only runs once, when it's first loaded statically by the VM/Class loader.

提交回复
热议问题