Significance of the keyword virtual - C#.NET

What is the significance of the keyword virtual in the method definition?

- The method with virtual keyword signifies that it can be overridden.

- Virtual keyword is a member function of a class.

- It is used in the base class method.

Example:
//base class
public virtual A()
{
   int a,b;
   int c = a + b;
   Console.WriteLine(c);
}

//derived class
public override A()
{
   int a,b
   int c = a * b;
   Console.WriteLine(c);
}

- Virtual keyword is used to modify a method, property, indexer or event declaration.

- The implementation of a virtual member can be changed by an overriding member in a derived class.
Allow class to be inherited and prevent method from being over-ridden - C#.NET
C#.NET - How can you allow class to be inherited and prevent the method from being over-ridden? - Declare the class as public and make the methods sealed...
What is an interface class? - C#.NET
C#.NET - What is an interface class? - An interface class is an abstract class with public abstract methods...
Difference between an interface and abstract class - C#.NET
C#.NET - Difference between an interface and abstract class - In the interface all methods must be abstract...
Post your comment