Sunday, February 2, 2014

Polymorphism - Programming Code

Simple Programming Codes 

Polymorphism - Programming Code :-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace polymorphism
{
    class Employee
    {
        public string FirstName = "FN";
        public string LastName = "LN";

        public virtual void PrintFullName()
        {
            Console.WriteLine(FirstName + " " + LastName);
        }
    }
    class FullTimeEmployee : Employee
    {
        public override void PrintFullName()
        {
            Console.WriteLine(FirstName + " " + LastName + "-Full Time Employee");
        }
    }

    class PartTimeEmployee : Employee
    {
        public override void PrintFullName()
        {
            Console.WriteLine(FirstName + " " + LastName + "-Part Time Employee");
        }
    }

    class TemporaryEmployee : Employee
    {

    }

    class Program
    {
        static void Main(string[] args)
        {
            Employee[] emp = new Employee[4];
            emp[0] = new Employee();
            emp[1] = new FullTimeEmployee();
            emp[2] = new PartTimeEmployee();
            emp[3] = new TemporaryEmployee();

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

        }
    }
}

then output will be like :
FN LN
FN LN - Full Time Employee
FN LN - Part Time Employee
FN LN


*** T
his is very simple codenext i will post again Polymorphism Program code,            Thank you... ***


No comments:

Post a Comment