Java – Static Block

Static block:

  • Define a block with static-keyword.
  • JVM invokes when class execution starts.
  • Static block executes before main() method.
class Pro
{
            static{
                        System.out.println(“Static block”);
            }
            public static void main(String args[]){
                        System.out.println(“Main method”);
            }
}
Output:   
        Static Block
        Main method
Scroll to Top