Sunday 18 December 2016

Difference between Constructors and Static block


1. Constructor - Called when we create object for the class
    Static block - Called when the class is loaded in the memory even before the constructor.

2. Constructor - Name of the constructor should be same as the class name.
     Static block - No name is there for static block. Only static{} keyword is used for the declaration.

3. Constructor - Multiple constructor with different signatures can be present in same class.
     Static block - There can be many static block in a class.

No comments: