0% found this document useful (0 votes)
26 views6 pages

Execution Order of Java Class

Static blocks are executed first when a class is loaded, followed by the constructor which initializes instance variables when an object is created, and then instance blocks which also initialize instance variables but are executed each time a new object is created. The static block is executed only once at class loading while constructors and instance blocks are executed whenever a new object is instantiated.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views6 pages

Execution Order of Java Class

Static blocks are executed first when a class is loaded, followed by the constructor which initializes instance variables when an object is created, and then instance blocks which also initialize instance variables but are executed each time a new object is created. The static block is executed only once at class loading while constructors and instance blocks are executed whenever a new object is instantiated.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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.

Static Block  Constructor  Instance Block

• Thank You •

You might also like