Friday, 23 December 2016

Polymorphism

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

namespace OopsConcept
{
    class Polymorphism
    {

    }
    ////compie time polymorphis start here
    //public class Class1
    //{
    //    public void NumbersAdd(int a, int b)
    //    {
    //        Console.WriteLine(a + b);
    //    }
    //    public void NumbersAdd(int a, int b, int c)
    //    {
    //        Console.WriteLine(a + b + c);
    //    }
    //}
    //public class Compiletimepolymorphis
    //{
    //    public static void main(string[] args)
    //    {
    //        Class1 objClass1 = new Class1();
    //        objClass1.NumbersAdd(12,5);
    //        objClass1.NumbersAdd(12, 12, 13);
    //    }
    //}

    ///Compile time poly morphis end here
    ///
    ///Run time poly morphis star here
    ///
    public class Bclass
    {
        public virtual void Sample1()
        {
            Console.WriteLine("Base Class");
        }
    }
    // Derived Class
    public class DClass : Bclass
    {
        public override void Sample1()
        {
            Console.WriteLine("Derived Class");
        }
    }
    // Using base and derived class
    class ProgramPloy
    {
        static void MainPlohy(string[] args)
        {
            // calling the overriden method
            DClass objDc = new DClass();
            objDc.Sample1();
            // calling the base class method
            Bclass objBc = new DClass();
            objBc.Sample1();
          
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment