Back to Developer Roadmap

Initializer Block

src/data/roadmaps/java/content/initializer-block@dg_UpaO8TzIN7w_QZ1n-6.md

4.0865 B
Original Source

Initializer Block

An initializer block in Java is a block of code, enclosed in curly braces {} , that is executed when an instance of a class is created. It's used to initialize instance variables or perform setup tasks before the constructor is called. There are two types: instance initializer blocks, which run every time a new object is created, and static initializer blocks, which run only once when the class is first loaded.

Visit the following resources to learn more: