Example #1
0
        static void Main(string[] args)
        {
            FullTimeEmployee f1 = new FullTimeEmployee();

            f1.fname = "Abishek";
            f1.lname = "Mahato";
            f1.PrintFullName();

            PartTimeEmployee p1 = new PartTimeEmployee();

            p1.fname = "Shankar";
            p1.lname = "Narayan";
            //p1.PrintFullName();
            ((Employee)p1).PrintFullName();//calling base class function, no method hiding or another methodis:

            //Employee pp1 = new PartTimeEmployee();//another method
            //pp1.fname = "Shankar";
            //pp1.lname = "Narayan";
            //pp1.PrintFullName();
        }
Example #2
0
        static void Main(string[] args)

        {
            Employee[] employees = new Employee[4]; //array of Employee type
            employees[0] = new Employee();
            employees[1] = new PartTimeEmployee();  //parent class pointing to child object
            employees[2] = new FullTimeEmployee();  //parent class pointing to child object
            employees[3] = new TemporaryEmployee(); //parent class pointing to child object


            foreach (Employee e in employees)
            {
                e.PrintFullName();
            }
            //even though there are functions of their own versions in child classes too
            //it will not invoke function from child class, as base class variable is referencing child class!

            //now, after using virtual and override keywords
            //we are now able to call child class methods from
            //base class reference variable pointing to child object.//polymorphism
        }
Example #3
0
        static void Main(string[] args)
        {
            //Customer c1 = new Customer("Tom", "Quinn");
            //c1.printFullName();

            //Circle circle1 = new Circle(5);
            //float circleArea = circle1.calculateArea();
            //Console.WriteLine("The area of the first circle is: {0}.", circleArea);
            //Console.ReadLine();

            //Circle circle2 = new Circle(6);
            //float circleArea2 = circle2.calculateArea();
            //Circle.print();
            //Console.WriteLine("The area of the second circle is: {0}", circleArea2);
            //Console.ReadLine();

            //FullTimeEmployee FTE = new FullTimeEmployee();
            //FTE.firstName = "Fulltime";
            //FTE.lastName = "Employee";
            //FTE.printFullName();

            //PartTimeEmployee PTE = new PartTimeEmployee();
            //PTE.firstName = "Parttime";
            //PTE.lastName = "Employee";
            //PTE.printFullName();

            //Polymorphism examples from here
            Employee[] employees = new Employee[4];

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

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