0

How to use static block in Java?

5th Sep 2017, 5:59 PM
pankaj
pankaj - avatar
4 Respostas
+ 3
static initialization is being done when class is loaded by class loader and constructor when new instance is created
5th Sep 2017, 6:08 PM
Lucien
Lucien - avatar
+ 3
The static block is executed first as it's necessary while the class is loaded. After the Class is loaded and it comes to creating objects of that type, the main method is called from the constructor.
5th Sep 2017, 6:24 PM
Lucien
Lucien - avatar
+ 2
Only when the class is loaded, not when it's instantiated. Static is not related to class instances. (static means the member is bound to the class). The static block would run before the main method
5th Sep 2017, 6:24 PM
Rrestoring faith
Rrestoring faith - avatar
0
In static block create the static method so first static method call or main method??
5th Sep 2017, 6:12 PM
pankaj
pankaj - avatar