Global Reach India UAE USA UK Australia
C# Polymorphism in OOP – Method Overloading & Overriding Explained (2025)

C# Polymorphism in OOP – Method Overloading & Overriding Explained

What is Polymorphism in C#?

Polymorphism is one of the four fundamental pillars of C# Object-Oriented Programming, along with encapsulation, abstraction, and inheritance.

The word polymorphism means “many forms”. In C#, polymorphism allows a single method, function, or interface to behave differently based on the object that is calling it.

Polymorphism improves flexibility and allows developers to write cleaner, reusable, and scalable code without modifying existing logic.

Types of Polymorphism in C#

  • Compile-Time Polymorphism – Method Overloading
  • Runtime Polymorphism – Method Overriding

Compile-Time Polymorphism (Method Overloading)

Method overloading allows multiple methods with the same name but different parameter lists.

class Calculator
{
    public int Add(int a, int b)
    {
        return a + b;
    }

    public int Add(int a, int b, int c)
    {
        return a + b + c;
    }
}

✔ Same method name ✔ Different parameters ✔ Decision made at compile time

Runtime Polymorphism (Method Overriding)

Runtime polymorphism occurs when a derived class overrides a base class method using virtual and override keywords.

class Animal
{
    public virtual void Speak()
    {
        Console.WriteLine("Animal makes a sound");
    }
}

class Dog : Animal
{
    public override void Speak()
    {
        Console.WriteLine("Dog barks");
    }
}
Animal animal = new Dog();
animal.Speak(); // Output: Dog barks

✔ Base reference → Derived object ✔ Method resolved at runtime ✔ Core OOP behavior

Real-World Example of Polymorphism

A payment system uses the same Pay() method for different payment types.

abstract class Payment
{
    public abstract void Pay();
}

class CardPayment : Payment
{
    public override void Pay()
    {
        Console.WriteLine("Paid using card");
    }
}

class UpiPayment : Payment
{
    public override void Pay()
    {
        Console.WriteLine("Paid using UPI");
    }
}

The same method behaves differently depending on the object.

Advantages of Polymorphism

  • Improves scalability
  • Reduces code duplication
  • Enhances flexibility
  • Supports clean architecture
  • Encourages loose coupling

Polymorphism vs Encapsulation vs Abstraction

  • Polymorphism: Same method, different behavior
  • Encapsulation: Protects data
  • Abstraction: Hides complexity

Frequently Asked Questions (FAQ) – C# Polymorphism

1. What is polymorphism in C#?

Polymorphism in C# is an Object-Oriented Programming concept that allows a single method or interface to represent different behaviors depending on the object type. It enables flexibility and scalability in software design.

2. Why is polymorphism important in C#?

Polymorphism allows developers to write reusable, maintainable, and extensible code. It reduces code duplication and makes applications easier to upgrade.

3. What are the types of polymorphism in C#?

C# supports two types of polymorphism: compile-time polymorphism (method overloading) and runtime polymorphism (method overriding).

4. What is compile-time polymorphism?

Compile-time polymorphism occurs when the method call is resolved during compilation. Method overloading is the best example of compile-time polymorphism.

5. What is runtime polymorphism?

Runtime polymorphism occurs when the method call is resolved at runtime using base class references and overridden methods.

6. What is method overloading in C#?

Method overloading allows multiple methods with the same name but different parameter lists within the same class.

7. What is method overriding in C#?

Method overriding allows a derived class to provide a specific implementation of a virtual method defined in a base class.

8. Which keywords are used for polymorphism in C#?

The virtual, override, and abstract keywords are used to implement runtime polymorphism in C#.

9. Can polymorphism work without inheritance?

Compile-time polymorphism can work without inheritance, but runtime polymorphism always requires inheritance.

10. What is dynamic binding in C#?

Dynamic binding refers to resolving method calls at runtime based on the object type rather than the reference type.

11. What is a real-world example of polymorphism?

A payment system where the same Pay() method behaves differently for card payment, UPI, or cash is a real-world example of polymorphism.

12. Can interfaces be used for polymorphism?

Yes, interfaces are one of the most powerful ways to implement polymorphism in C# and are widely used in enterprise applications.

13. What is base class reference in polymorphism?

A base class reference is a variable of a base type that points to an object of a derived class, enabling runtime polymorphism.

14. Does polymorphism improve performance?

Polymorphism slightly increases runtime overhead, but the benefits of flexibility and maintainability far outweigh the performance cost.

15. Is polymorphism mandatory in OOP?

Polymorphism is not mandatory but is considered essential for writing scalable and maintainable object-oriented applications.

16. Can constructors be overridden in C#?

No, constructors cannot be overridden because they are not inherited by derived classes.

17. What is the difference between overloading and overriding?

Overloading happens in the same class at compile time, while overriding happens across classes at runtime.

18. How polymorphism helps in large applications?

Polymorphism allows developers to add new features without modifying existing code, which is critical for large and enterprise-level applications.

19. Is polymorphism used in real projects?

Yes, polymorphism is widely used in real-world projects, frameworks, APIs, and enterprise systems.

20. How polymorphism relates to abstraction?

Abstraction defines what actions an object can perform, while polymorphism defines how those actions behave differently in derived classes.

21. What are the advantages of polymorphism in C#?

Key advantages include code reusability, flexibility, scalability, reduced complexity, and better maintainability.

⚠️ Important Notice: SupportDeskWorld is an independent informational platform. We provide verified, publicly available guides, tutorials, and awareness content. We do not offer direct services, financial advice, legal work, repairs, or government assistance. For official inquiries, please use our Contact Page.
Scroll to Top