Static blocks in java
Introduction Hi everyone, it has been a while since I have put a new topic. In this blog post, I will be writing about static blocks in java. Static blocks is a block of code that get executed first when the class is loaded. Static block will be the first to execute when a class is called. Please check the below example. package com.blog.techjourney; public class StaticBlockExample { static { System.out.println( " Inside static block" ); } public static void main(String[] args) { System.out.println( " Inside main method" ); } } In the above example, the static block will get executed before the main method. The output of the above program is as follows: Inside static block Inside main method If there are more than one static block in a class, each of the static blocks get executed before the main method. The order of execution of the static block will be the same as t