What is the static block in Java?

Static block is used to initialize the static data member. It is executed before the main method, at the time of classloading.

  1. class A2{
  2.   static{System.out.println(“static block is invoked”);}
  3.   public static void main(String args[]){
  4.    System.out.println(“Hello main”);
  5.   }
  6. }
Output: static block is invoked
       Hello main