Overridding
What is mean overridding?With Example
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
rgowthamraj ramajayamPosted Nov 12, 2014, 7:37 AM
Joginder BangerPosted Nov 12, 2014, 6:35 AM
The C# language provides the override modifier for this purpose.
This keyword specifies that a method replaces its virtual base method.
using System;
class A
{
public virtual void Y()
{
// Used when C is referenced through A.
Console.WriteLine("A.Y");
}
} class B : A { public override void Y()
{ // Used when B is referenced through A.
Console.WriteLine("B.Y");
}
}
class C : A
{ public void Y()
// Can be "new public void Y()"
{
// Not used when C is referenced through A.
Console.WriteLine("C.Y");
}
}
class Program {
static void Main() {
// Reference B through A.
A ab = new B(); ab.Y();
// Reference C through A.
A ac = new C(); ac.Y();
}
}
Result B.Y A.Y
VulpesPosted Nov 12, 2014, 6:25 AM