Static block is used for initializing the static variables.
This block gets executed when the class is loaded in the memory.
A class can have multiple Static blocks
Static block is run immediately its loaded into memory(ie.,when class is
loaded into class loader), not when class is
created like a constructer. Its mostly used to initialize static variables
created in a class.
It is used to create another block before the main class.
every java codes runs here first.
Any code gets executed before the main class
static{
//code is placed between these brackets.
}
// to create static block in java
static{
// code to be executed is placed here
}
// its placed inside class. its executed whenever the class is created not when its object is created or called.