+ 3

What are the advantages of Static blocks in Java?

In Java we have different static blocks and initializers. Where should we use for what?

19th Nov 2018, 7:51 AM
Idris Tuna
2 Respostas
+ 6
You must have heard that in Java the main() method runs first. But if your code is having the static block then it will run before the main() method Static block is mainly used to initialize the static members
19th Nov 2018, 8:59 AM
Rishi Anand
Rishi Anand - avatar
+ 4
They make some initializations without taking cure if an instance of that class is created or not and usually contain dependencies (like load to native libraries or to global class variables) that have to inited only once time
19th Nov 2018, 8:21 AM
KrOW
KrOW - avatar