In this article, we will learn about the order of execution of blocks in Java.
Different blocks and their order of execution in Java Class
- Static Block
- Init Block(Anonymous Block)
- Constructor
The output of the above program
As you can see STATIC block will execute only once when a class gets loaded.
But Anonymous block and Constructor will run every time the object of a class gets created. Init block will get executed first and then constructor.
0 Comments