Home > DeveloperSection > Forums > Method overriding in c#
Ankit Singh

Total Post:341

Points:2389
Posted on    November-02-2015 9:52 PM

 .NET C# 
Ratings:


 1 Reply(s)
 405  View(s)
Rate this:
we wnat method overriding in c#


aditya kumar Patel

Total Post:250

Points:1782
Posted on    November-02-2015 10:14 PM

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");

}

}

}


Don't want to miss updates? Please click the below button!

Follow MindStick