public PolymorphismExample() { Employee[] employees = new Employee[4]; // Polymorphism allows you to invoke derived class methods through base class reference during runtime. // In the base class the method is declared 'virtual', and in the derived class we 'override' the same method. // The 'virtual' keyword indicates, the method can be overridden in any derived class. employees[0] = new Employee(); employees[1] = new PartTimeEmployee(); employees[2] = new FullTimeEmployee(); employees[3] = new TemporaryEmployee(); foreach (Employee e in employees) { e.PrintFullName(); } }
/* Polymorphism is one of the main pillars of OOPs. * Polymorphism enables you to invoke derived class method thru base class reference variable at run time. * In the base class, the method is declared as virtual and in the derived class we override the same method. * The virtual keyword indicates, the method can be overridden in any derived class. */ 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 TemporaryEmployee(); foreach (Employee e in employees) { /* * Here in employee array there are 4 different type of employee objects. * No any child class have print full name method even then, * it can invoke parent class method using the parent class referance variable. */ e.PrintFullName(); } Employee[] emp2 = new Employee[4]; emp2[0] = new Employee(); emp2[1] = new PartTimeEmployee(); emp2[2] = new FullTimeEmployee(); emp2[3] = new TemporaryEmployee(); foreach (var item in emp2) { item.SalaryCycle(); } }
public void Put([FromBody] TemporaryEmployee temporaryEmployee) { _temporaryEmployee.UpdateEmployee(temporaryEmployee); }
public void Post([FromBody] TemporaryEmployee temporaryEmployee) { _temporaryEmployee.InsertEmployee(temporaryEmployee); }
public void UpdateEmployee(TemporaryEmployee employee) { _context.UpdateTemporaryEmployee(employee); }
public void InsertEmployee(TemporaryEmployee employee) { _context.AddTemporaryEmployee(employee); }