Edukot is free and open to everyone, but you must be registered in Edukot to get extra privileges like Asking questing,Answering, voting, posting, commenting and many more......
Share What You Know With Others. Help Others, Get Helped !
What is constructor?
Constructor is a block of code that allows you to create an object of class. This can also be called creating an instance. Constructor looks like a method but it’s not, for example methods can have any return type or no return type (considered as void) but constructors don’t have any return type not even void.
There are basically two rules defined for the constructor.
1. Constructor name must be same as its class name
2. Constructor must have no explicit return type
There are two types of constructors:
1. Default constructor (no-arg constructor)
2. Parameterized constructor