What do you mean by virtual modifier in C# programming language?

 Posted by Goud.Kv on 9/3/2014 | Category: C# Interview questions | Views: 1711 | Points: 40
Answer:

In order to modify any type or field and allow that to override by any other derived class, virtual modifier is used. A virtual method can be accessed by any derived classes and can redefine it.

Example,
class MyClass

{
protected virtual void Test() // Virtual method declaration
{
..............;
............;
}
}
class SubClass : MyClass
{
protected override void Test() // overriding method from 'MyClass' class
{
..............;
............;
}
}


Asked In: Spotted While Learning | Alert Moderator 

Comments or Responses

Login to post response