Some facts about Virtual methods.

 Posted by Raja on 5/11/2010 | Category: C# Interview questions | Views: 6710
Answer:

Virtual keyword is used to declare a method inside the base class that can be overridden.

Following conditions are applied to a virtual method

1. Virtual method can not be declared as Private
2. Virtual method can not be declared as Static
3. Virtual method may or may not be overridden.
4. In order to override the virtual method of the base class, Override keyword is used provided the method signature of the derived class is same as base class, even the access modifier should be same.
5. A Virtual method must contain the method body otherwise compiler shall throw error.
6. Virtual keyword is only used in base and derived class scenario where you want your method over-ridable in the derived class.

Enjoy virtual keyword :)


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response