If we want to initialize an instance then we should define constructor inside class.
Constructor looks like method but it is not considered as method.
Constructor is special
It’s name is same as that of class name.
It does not return anything, not even void.
It is designed to be called implicitly i.e it gets called automatically when instance of the class is created.
It is called once per instance.
We can not call constructor on instance explicitly.
Example:
Employee employee=new Employee();
employee.Employee(); not ok
typesofconstructor
Comments
Post a Comment