Introduction
In C#, a constructor is a special method in a class that initializes objects.
When a class has multiple constructors with different parameters, it is known as Constructor Overloading — a type of compile-time polymorphism.
This concept is commonly used in real-world applications to create objects in different ways, depending on the information available at the time of creation.
Objective
To define multiple constructors in a class.
To understand how constructor overloading works in C#.
To implement it using a real-time ASP.NET WebForms example.
C# WebForms Real-Time Example
Step 1: ASPX Page (ConstructorOverloadingDemo.aspx)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ConstructorOverloadingDemo.aspx.cs" Inherits="WebApp.ConstructorOverloadingDemo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Constructor Overloading Example</title>
</head>
<body>
<form id="form1" runat="server">
<div style="font-family: Arial; margin: 40px;">
<h2>Constructor Overloading in C# WebForms</h2>
<asp:Button ID="btnShow" runat="server" Text="Show Constructor Output" OnClick="btnShow_Click" /><br /><br />
<asp:Label ID="lblResult" runat="server" Font-Names="Consolas" Font-Size="Large"></asp:Label>
</div>
</form>
</body>
</html>
Step 2: Code-Behind (ConstructorOverloadingDemo.aspx.cs)
using System;
namespace WebApp
{
public partial class ConstructorOverloadingDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnShow_Click(object sender, EventArgs e)
{
string result = "";
// Using default constructor
Student s1 = new Student();
result += "<b>Default Constructor:</b><br/>" + s1.DisplayDetails() + "<br/><br/>";
// Using parameterized constructor (2 parameters)
Student s2 = new Student("Sandhiya", 22);
result += "<b>Parameterized Constructor (Name, Age):</b><br/>" + s2.DisplayDetails() + "<br/><br/>";
// Using parameterized constructor (3 parameters)
Student s3 = new Student("Priya", 23, "BCA");
result += "<b>Parameterized Constructor (Name, Age, Course):</b><br/>" + s3.DisplayDetails();
lblResult.Text = result;
}
}
// Step 3: Student class with constructor overloading
public class Student
{
public string Name;
public int Age;
public string Course;
// Default constructor
public Student()
{
Name = "Unknown";
Age = 0;
Course = "Not Assigned";
}
// Parameterized constructor (2 parameters)
public Student(string name, int age)
{
Name = name;
Age = age;
Course = "Not Assigned";
}
// Parameterized constructor (3 parameters)
public Student(string name, int age, string course)
{
Name = name;
Age = age;
Course = course;
}
public string DisplayDetails()
{
return $"Name: {Name}<br/>Age: {Age}<br/>Course: {Course}";
}
}
}

Join the conversation! Your thoughts help the community grow.