Tuesday 24 January 2017

METHOD HIDING IN C# WITH SAMPLE EXAMPLE

## METHOD HIDING

## INVOKE BASE CLASS MEMBERS


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication4;

namespace ConsoleApplication4
{
    public class Employee
    {
        public string FirstName;
        public string LastName;
        public string Email;

        public void PrintFullName()
        {
            Console.WriteLine(FirstName + " " + LastName);
        }
    }

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

    public class FullTimeEmployee : Employee
    {

    }
    class Program
    {
        static void Main(string[] args)
        {
           Employee PTE = new PartTimeEmployee();
            PTE.FirstName = "PART TIME ";
            PTE.LastName  =  "EMPLOYEE";
            PTE.PrintFullName();
            Console.ReadLine();

            FullTimeEmployee FTE = new FullTimeEmployee();
            FTE.FirstName = "FULL TIME";
            FTE.LastName = "EMPLOYEE";
            FTE.PrintFullName();
            Console.ReadLine();
        }

    }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.