static void Main(string[] args) { Empolyee[] emp = new Empolyee[4]; //Creating an Array of Employees emp[0] = new Empolyee(); // here reference is Employee class and objects are of different classes //The PrintName() methods in different classes are not called because the reference is employee class //To call the methods(not constructors) of different classes we have to override the methods and make Employee class methods as virtual emp[1] = new FullTimeEmployee(); // the FullTimeEmployee will be called and PrintName() methods in it is called as it is overidden emp[2] = new PartTimeEmployee(); emp[3] = new TemporaryEmployee(); TemporaryEmployee temp = new TemporaryEmployee(); temp.PrintName(); PartTimeEmployee pte = new PartTimeEmployee(); pte.PrintName(); foreach (Empolyee e in emp) { e.PrintName(); } Console.ReadLine(); }
static void Main(string[] args) { //Console.WriteLine("Hello World!"); FullTimeEmployee FTE = new FullTimeEmployee(); FTE.FirstName = "Hi!"; FTE.LastName = "There"; FTE.YearlySalary = 50000000; FTE.PrintName(); PartTimeEmployee PTE = new PartTimeEmployee(); PTE.FirstName = "Hi!"; PTE.LastName = "There PTE"; PTE.PrintName(); // We can also typecast and convert the ChildClass into ParentClass and call the methods of Parent Class. ((Empolyee)PTE).PrintName(); // One more way to call ParentClass Method using ChildClass when there is similiar name present // as child is a specilaization of parent class, we can use object of ChildClass where reference type is Parent Empolyee PTE1 = new PartTimeEmployee(); // reference is parent and object is child class but vice-versa is not possible PTE1.FirstName = "Hi!"; PTE1.LastName = "There PTE1"; PTE1.PrintName(); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); FullTimeEmployee FTE = new FullTimeEmployee(); FTE.FirstName = "Hi!"; FTE.LastName = "There"; FTE.YearlySalary = 50000000; FTE.PrintName(); Console.ReadLine(); }