Polymorphism

dose the below sentence simply describes the meaning of Polymorphism
 polymorphism is a Opp pillar that treats the objects created from derived class as a  base class  at runtime

as an example in here the reference variable is pointing to the Employee base class while at run time the method is called on the PartTimeEmployee() type correct ?
c#
public class Employee 
{
    public string? firstName = "FN";
    public string? lastName = "LN";

    public virtual void PrintFullName()
    {
        Console.WriteLine(firstName + " " + lastName);
    }
}

public class PartTimeEmployee: Employee 
{
    public override void PrintFullName()
    {
        Console.WriteLine(firstName + " " + lastName + " - PartTime");
    }
}
Employee employee = new PartTimeEmployee();

employee.PrintFullName();

and that is polymorphisim we have a base class method in one class(type) that can have many forms in drived class and the type that the method are called from is defined at runtime
Was this page helpful?