SIB(STATIC INITIALIZATION BLOCK )

 
A static initialization block is a normal block of code enclosed in braces, { }, and preceded by the static keyword. Here is an example:
static {
// whatever code is needed for initialization goes here
}
A class can have any number of static initialization blocks, and they can appear anywhere in the class body. The runtime system guarantees that static initialization blocks are called in the order that they appear in the source code.
There is an alternative to static blocks - you can write a private static method:
class Whatever {
public static varType myVar = initializeClassVariable();
private static varType initializeClassVariable() {
// initialization code goes here
}
}
The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable.
 
1
2
3
4
5
6
7
8
9
10
11
class StaticInitializationBlock
    {
        static
       {
    System.out.println("SIB");
        }
        public static void main(String[] args)
            {
       System.out.println("Hello World!");
            }
    }

O/P:

static inittialization block

NOTE:As we know Static initialization blocks are always executed before the execution of any method or any other member of class so, first it will print SIB and after that main() method get executed so it will print Hello World!.