Constructor
Definition and functions of constructor in programming
So far, all the methods we have seen will work (execute) only when we call them. If we define a method but do not call it, the code inside the method will not execute. However, there is one method that executes without calling. This method is known as the constructor of the class.
A constructor is a method that has the same name as that of the class. A constructor does not have any return type, not even void. However, a constructor can take arguments.
Constructors are normally used for providing some valid values to the fields of the class. We can create a constructor as -
public class-name(arguments) { }
For example, a constructor for our `Person' class can be defined as -
public Person() { statements of the constructor; } What else we need to know
If we understand the basic concepts of classes, objects, properties and methods, we can use the .NET Framework classes to develop ASP.NET pages. However, there is much more to object-oriented programming. Advanced concepts like inheritance, static members, delegates, interfaces and polymorphism constitute a major part of the object-oriented programming. A detailed discussion of all these topics is not possible in this tutorial and we can develop ASP.NET pages without this knowledge. It is however, a good thing to go on and learn about them, as this will help us to create more powerful and professional applications.