private static void Main(string[] args) { FullTimeEmployee fte = new FullTimeEmployee(); fte.PrintMethod(); // this will call FullTimeEmployee.PrintMethod() ((Employee)fte).PrintMethod(); // this will call Employee.PrintMethod(); Employee emp = new FullTimeEmployee(); emp.PrintMethod(); // Employee.PrintMethod() will be called }
static void Main(string[] args) { FullTimeEmployee fte = new FullTimeEmployee(); fte.FirstName = "Fulltime"; fte.LastName = "Employee"; fte.PrintFullName(); //PartTimeEmployee pte = new PartTimeEmployee(); //Parent class reference variables can point to child class objects //a parent class reference variable can point to a child class object Employee pte = new PartTimeEmployee(); pte.FirstName = "PartTime"; pte.LastName = "Employee"; //Typecasting //((Employee)pte).PrintFullName(); }
static void Main(string[] args) { FullTimeEmployee FTE = new FullTimeEmployee(); FTE.FirstName = "First FTE"; FTE.LastName = "Last FTE"; FTE.PrintFullName(); PartTimeEmployee PTE = new PartTimeEmployee(); PTE.FirstName = "First PTE"; PTE.LastName = "Last PTE"; PTE.PrintFullName(); /*you can convert a type child operator to a parent type by doing this*/ ((Employee)PTE).PrintFullName(); /*Sincee a child class object can cover all the things from parent class we can allso do this:*/ Employee PTE1 = new PartTimeEmployee(); PTE1.FirstName = "First PTE"; PTE1.LastName = "Last PTE"; PTE1.PrintFullName(); System.Console.ReadLine(); /*Remember you can't do PartTimeEmployee PTE = new Employee(); because parents will not have all the features of the child class.*/ }