Example #1
0
        public static void Main()
        {
            // Instantitated a list of type Employee with a size of 5.
            Employee[] employees = new Employee[5];

            // Instantiated a FullTimeEmployee and
            // assigned it to the first item of employees list.
            employees[0] = new FullTimeEmployee();
            // Modified FirstName and LastName using properties.
            employees[0].FirstName = "Dan";
            employees[0].LastName  = "Bahrt";

            employees[1]           = new PartTimeEmployee();
            employees[1].FirstName = "Ted";
            employees[1].LastName  = "Kim";

            employees[2]           = new TemporaryEmployee();
            employees[2].FirstName = "Snoop";
            employees[2].LastName  = "Dogg";

            employees[3]           = new InternEmployee();
            employees[3].FirstName = "John";
            employees[3].LastName  = "Doe";

            // Did not change FirstName or LastName.
            // Using default FirstName and LastName.
            employees[4] = new Employee();

            // Calls overridden PrintFullName methods from each derived classes.
            foreach (Employee e in employees)
            {
                e.PrintFullName();
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Employee[] employees = new Employee[4];
            employees[0] = new FullTimeEmployee();
            employees[1] = new PartTimeEmployee();
            employees[2] = new TemporaryEmployee();

            foreach (Employee emp in employees)
            {
                emp.PrintFullName();
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            Employee[] e = new Employee[3];
            e[0] = new Employee();
            e[1] = new FullTimeEmployee();
            e[2] = new PartTimeEmployee();

            foreach (Employee em in e)
            {
                em.PrintFullName();
            }
        }
Example #4
0
        public static void Main()
        {
            Employee[] employees = new Employee[4];

            employees[0] = new Employee();
            employees[1] = new PartTimeEmployee();
            employees[2] = new FullTimeEmployee();
            employees[3] = new TemporaryTimeEmployee();

            foreach (Employee employe in employees)
            {
                employe.PrintFullName();
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            Employee[] E = new Employee[4];   //Array of objects
            E[0] = new Employee();
            E[1] = new PartTimeEmployee();
            E[2] = new FullTimeEmployee();
            E[3] = new TemporaryEmployee();

            foreach (Employee e in E)
            {
                e.PrintFullName();
            }
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Employee[] E = new Employee[4];   //Array of objects
            E[0] = new Employee();
            E[1] = new PartTimeEmployee();
            E[2] = new FullTimeEmployee();
            E[3] = new TemporaryEmployee();

            foreach (Employee e in E)
            {
                e.PrintFullName();
            }
            Console.ReadKey();
        }
Example #7
0
 static void Main(string[] args)
 {
     /*since all the emplooyes are of type Employee (parent) we would have to use over ride key word for all the methods in derived class and use
      * virtual key word for the method in parent class*/
     Employee[] employees = new Employee[4];
     employees[0] = new Employee();
     employees[1] = new PartTimeEmployee();
     employees[2] = new FullTimeEmployee();
     employees[3] = new TemperoryEmployee();
     foreach (Employee e in employees)
     {
         e.PrintFullName();
     }
     System.Console.ReadLine();
 }
Example #8
0
        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 employee in employees)
            {
                employee.functionPrintFullName();
            }
            Console.Read();
        }
Example #9
0
        static void Main(string[] args)
        {
            Employee[] objEmployee = new Employee[4];
            objEmployee[0] = new Employee();
            objEmployee[1] = new FullTimeEmployee();
            objEmployee[2] = new PartTimeEmployee();
            objEmployee[3] = new TemporaryEmployee();

            foreach (Employee e in objEmployee)
            {
                e.PrintFullName();
            }

            Console.ReadKey();
        }
Example #10
0
        static void ImplementPolymorphism()
        {
            Employee[] employees = new Employee[4];
            employees[0] = new Employee();

            // Creating Parent/Base class reference to Child/Derived class Object
            employees[1] = new FullTimeEmployee();
            employees[2] = new PartTimeEmployee();
            employees[3] = new TemporaryEmployee();

            foreach (Employee e in employees)
            {
                e.PrintFullName();
            }
        }
Example #11
0
        static void Main()
        {
            //Employee E = new Employee();
            //E.PrintFullName();

            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)
            {
                e.PrintFullName();
            }
        }
Example #12
0
        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)
            {
                //Instead of override if we use hiding, Since the reference variable is of type Base class, the base class method is called for all instances
                e.PrintFullName();
            }

            Console.ReadKey();
        }
Example #13
0
        private static void Main(string[] args)
        {
            /*
             * Polymorphism allows us to invoke derived class method through a base class reference
             * during runtime
             */

            Employee[] employees = new Employee[4];

            employees[0] = new Employee();
            employees[1] = new FullTimeEmployee();
            employees[2] = new PartTimeEmployee();
            employees[3] = new TemproryEmployee();

            for (int i = 0; i < employees.Length; i++)
            {
                employees[i].PrintMethod();
            }
        }
Example #14
0
        static void Main(string[] args)
        {
            //Employee e = new Employee();
            //e.PrintFullNmae();


            //Polymorphism enables you to envoke derived class methods
            //through base class methods at run time. if the child class
            //if the child class is overriding the base class method.
            Employee[] employees = new Employee[4];
            employees[0] = new Employee();
            employees[1] = new PartTimeEmployee();
            employees[0] = new FullTimeEmployee();
            employees[0] = new TemporaryEmployee();

            foreach (Employee e in employees)
            {
                e.PrintFullNmae();
            }
        }