using System;
//Polymorphism
// allows you to invoke drived class methods through a base class reference during runtime
// in the base class the method is declared virtula,
// and in the derived class we override the same method
// the virtual keyword indicates, the method can be overriden in any derived class
public class Employee
{
public string FirstName = "FN";
public string LastName = "LN";
public virtual void PrintFullName() //for override
{
Console.WriteLine(FirstName + " " + LastName);
}
}
public class PartTimeEmployee : Employee
{
public override void PrintFullName() //using override keyword
{
Console.WriteLine(FirstName + " " + LastName + " - Part Time");
}
}
public class FullTimeEmployee : Employee
{
public override void PrintFullName()
{
Console.WriteLine(FirstName + " " + LastName + " - Full Time");
}
}
public class TemporatyEmployee : Employee
{
//if there is now method then called base method
public override void PrintFullName()
{
Console.WriteLine(FirstName + " " + LastName + " - Temporary");
}
}
public class Program
{
static void Main(string[] args)
{
Employee[] employees = new Employee[4];
employees[0] = new Employee();
employees[1] = new PartTimeEmployee();
employees[2] = new FullTimeEmployee();
employees[3] = new TemporatyEmployee();
foreach (Employee e in employees)
{
e.PrintFullName();
}
}
}