Home / java / Order of execution of java members

Order of execution of java members

members of a class
1. properties(static and instance)
2. methods (static and instance)
3. constructors.
4. blocks. (static and instance)

//first variable and property.
order:
1. static properties are initialized.
2. static blocks are executed.
3. static methods are executed only when we call them.
we can use static methods to initialize properties. And we call static methods within the static block.
Note:: static methods are called before blocks if we use them to initialize the properties.
4. instance properties are initialized.
5. instance blocks are executed.
6. constructors are executed.
7. instance methods are executed only when we call by using instance.

Note:: instance methods are called before constructor and before
blocks if we use them to initialize instance properties.

we can not call instance members in static members why because by the time we are executing static members there is no guaranty of object
availability. The reverse is possible.

About Mohammad Fareed

Software Engineer @ Tekzenit.

Check Also

What is Mutable and Immutable ?

1.what is the Difference between String and StringBuffer? Ans: 1. The string is immutable whereas …

Leave a Reply

Your email address will not be published. Required fields are marked *