Execution Order of Java Class
Execution Order of Java Class
Sequence of execution of
• Static Block
• Constructor
• Instance Block
Static Keyword
• The users can apply static keywords with variables, methods, blocks, and nested classes.
• When a member is declared static, it can be accessed before any objects of its class are created, and
without reference to any object.
• A static block gets executed exactly once, when the class is first loaded.
Constructor
• A constructor is similar to method and it is invoked at the time creating an object of the class, it is generally
used to initialize the instance variables of a class.
Instance Block
• Instance Initializer block is used to initialize the instance data member. It run each time when object of the
class is created.
Execution Flow :
The static blocks are executed first, followed by constructors and then the
instance methods.
• Thank You •