Java static block



static keyword can be used to create a block to be used to initialize static variables.

 This static block executes when classloader loads the class. A static block is invoked before main() method. You can verify the same using.

Example

Live Demo

public class Tester {
   static {
      System.out.println("In static block");
   }
   public static void main(String[] arguments) {
      System.out.println("In main");
   }
}  



Advertisements