Tuesday, 21 February 2017

method overriding example in c#

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

namespace ConsoleApplication34
{
    public class bc
    {
        public virtual void display()
        {
            Console.WriteLine("iam virtual method");
        }
    }
    public class dc : bc
    {
        public override void display()
        {
            Console.WriteLine("iam override method");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            bc b;
            b = new bc();
            b.display();

            b = new dc();
            b.display();

        }
    }
}

Output screen:




No comments:

Post a Comment