• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.


What's Overriding for .NET? I am begginer and trying to learn .Net and yesterday someone asked me this question. What is this? Any answers will be appreciated. Thanks in advance!!
overriding is the one of the feature of the OOPS(object oriented programming) . here we explain the overriding
Here:In the example, the class A is the base class. It has the virtual method Y.
And:In class B, we override Y. In class C, we implement Y but do not specify that it overrides the base method.

Program that uses override modifier: C#

using System;

class A
public virtual void Y()
// Used when C is referenced through A.

class B : A
public override void Y()
// Used when B is referenced through A.

class C : A
public void Y() // Can be "new public void Y()"
// Not used when C is referenced through A.

class Program
static void Main()
// Reference B through A.
A ab = new B();

// Reference C through A.
A ac = new C();



In this example, the A type is used to reference the B and C types. When the A type references a B instance, the Y override from B is used. But when the A type references a C instance, the Y method from the base class A is used.
Note:The override modifier was not used.
The C.Y method is local to the C type.
Warning:In the above program, the C type generatesa warning because C.Y hides A.Y. Your program is confusing and could be fixed.
Tip:If you want C.Y to really "hide" A.Y, you can use the new modifier, as in "new public void Y()" in the declaration.