What is Constructor?
Raj Kumar M
A construcor is a method that returns nothing, It is used to instanciate an object and also helps us to perform some tasks exactly when the object is instanciated example: class MyClass { //no constructor ............... } When I want instanciate an object I can't example: MyClass object = new ? class MyClass { MyClass() {MessageBox("Hi I'm MyClass instance")} } MyClass object = new MyClass() When I execute the program the first think done is to display message "Hi I'm MyClass instance"
When we create instance of class a special method of that class, called that is constructor. Similarly, when the class is destroyed, the destructor method is called. These are general terms and usually not the actual member names in most object-oriented languages. It is initialized using the keyword New, and is destroyed using the keyword Finalize