METHOD OVERRIDING IN C#

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C# 
 892  View(s)
Ratings:
Rate this:
we wnat method overriding in c#
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: Method overriding in c#

    Override affects virtual method usage. Virtual methods are meant to be re-implemented in derived classes. The override keyword specifies that a method replaces its virtual base method.

    
    

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Net;

    using System.Text;

    using System.Threading;

    namespace Forum

    {

    class Program

    {

    static void Main(string[] args)

    {

    First F_obj = new First();

    F_obj.method1();

    // Reference Second through First.

    First S_obj = new Second();

    S_obj.method1();

    Console.ReadLine();

    }

    }

    class First

    {

    public virtual void method1()

    {

    Console.WriteLine("Call First class method1 ");

    }

    }

    class Second : First

    {

    public override void method1()

    {

    Console.WriteLine("Call Second class method1");

    }

    }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!