Java static block

Java Programming Java8Object Oriented Programming

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");
   }
}  


raja
Published on 22-Apr-2018 19:51:09
Advertisements