Polymorphism
Polymorphism
The word polymorphism comes from Greek and means having several different
forms. This is one of the essential concepts of object-oriented programming.
Where inheritance is related to classes and (their hierarchy), polymorphism is
related to object methods.
When overriding, you change the method behavior for a derived class.
e.g Clas owais
{
Virtual void hi(int a)
{
}
}
Class khan:owais
{
public overrid void hi(int a)
{
}
}
Overloading simply involves having a method with the same name within the
class.
Class A
{
class a()
}
class a(int a)
{
}
}
Example 1:
using System;
public class Customer
{
public virtual void CustomerType()
{
Console.WriteLine("I am a customer");
}
}
public class CorporateCustomer : Customer
{
public override void CustomerType()
{
Console.WriteLine("I am a corporate customer");
}
}
public class PersonalCustomer : Customer
{
public override void CustomerType()
{
Console.WriteLine("I am a personal customer");
}
}