Static and Non Static Block:
A static block is a special block that gets executed once when the class is loaded into memory. It's used to initialize static variables or to perform setup operations
before the main method runs.
A block is a group of statements enclosed within curly braces {}. It defines a scope where variables can be declared and logic can be grouped.
Block and Constructor are called when an object is created.
Order of Execution:
Static block(s) → executed when the class is loaded (only once).
Instance block(s) → executed every time an object is created, before the constructor.
Constructor → executed after instance blocks when an object is created.
Main method → executed after class loading and static block execution.
Top comments (0)