Constructor Overloading
using System;
// Constructor overloading is the process of creating multiple constructors which differ in number or type of arguments
class BaseClass
{
BaseClass()
{
Console.WriteLine("constructor with no parameter");
}
BaseClass(int i)
{
Console.WriteLine("constructor receiving integer parameter "+i);
}
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 100
constructor receiving integer parameter 100 and string parameter HELLO WORLD..!!