- Static constructor
- Instance constructor (non-static constructor)
Static constructor
- Does not take access modifiers
- Cannot access any non static members
- Static constructor will get called as soon as we create an instance of the class or we refer the class
- class which implements static constructor does not has to be static.
- static constructor calls only once.
- it can be used for initializing objects
eg, say there is an employee class, and we want to know how many employee object's are created. This case you can create a static integer variable and increment the count.
No comments:
Post a Comment