Constructor
using System;
// Constructor is used to initialize objects. It has the same name as the class name
class BaseClass
{
BaseClass()
{
Console.WriteLine("constructor with no parameter");
}
BaseClass(int i)
{
Console.WriteLine("constructor receiving integer parameter");
}
BaseClass(int i, string message)
{
Console.WriteLine("constructor receiving integer parameter " + i + " and string parameter " + message);
}
static void Main(string[] args)
{
Console.WriteLine("Example of overloading");
BaseClass ch1 = new BaseClass();
BaseClass ch2 = new BaseClass(100);
BaseClass ch3 = new BaseClass(100, "HELLO WORLD..!!");
Console.ReadLine();
}
}
Output:
Example of overloading
constructor with no parameter
constructor receiving integer parameter
constructor receiving integer parameter 100 and string parameter HELLO WORLD..!!