MY mENU


Thursday 9 February 2012

Difference between Constructor and Static


The static block will be executed at compiletime when the class is loaded on to the JVM. It is executed only once.
Constructor will be executed at Runtime while creating the object. The constructor is called only once for an object and it is called as many times as you create the object.
Ex: if a class Test is having one static block and a constructor. Then the static block is executed only once. If you create three objects based on Test class then the constructor is called three times.

No comments:

Post a Comment