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.


Live Demo

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

Updated on 05-Mar-2020 12:20:32