.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Interview Question >> C# >> Post New Question Subscribe to Interview Questions

What does the keyword virtual mean in the method definition?

Posted By :Muthu     Posted Date :November 02, 2010    Points :10   Category :C# 
The method can be over-ridden.

You can also find related Interview Question to What does the keyword virtual mean in the method definition?  below: 

What is the keyword used in VB to carry out the work of virtual keyword of C#?

The Overridable keyword. It declare a method to support polymorphism. (More...)

To define abstract method which keyword is used in VB?

MustOverride keyword is used to define an abstract method in VB. (More...)

What is the meaning of virtual keyword?

It means that the method and the properties can be overriden. (More...)

All about Virtual Keyword

When we need to override a method of the base class in the sub class, then we give the virtual keyword in the base class method. This makes the method in the base class to be overridable.

· Methods, properties, and indexers can be virtual, which means that their implementation can be overridden in derived classes.

· You cannot use the virtual modifier with the following modifiers: Static, Abstract, Override (More...)

Define Virtual Method

used to declare a method inside the base class that can be overridden.
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. (More...)

What is use of Virtual,sealed,override,abstract keyword?

The use of virtual keyword is to enable or to allow a class to be overridden in the derived class.
The use of sealed keyword is to prevent the class from overridden i.e. you can't inherit sealed classes.
The use of override keyword is to override the virtual method in the derived class.
The use of abstract keyword is to modify the class, method, and property declaration. You cannot directly make calls to an abstract method and you cannot instantiate an abstract class. (More...)

What is Method overloading?

Method overloading occurs when a class contains two methods with the same name, but different signatures. (More...)

What is Method Overriding? How to override a function in C#?

Use the override modifier to modify a method, a property, an indexer, or an event. An override method provides a new implementation of a member inherited from a base class. The method overridden by an override declaration is known as the overridden base method. The overridden base method must have the same signature as the override method.
You cannot override a non-virtual or static method. The overridden base method must be virtual, abstract, or override. (More...)

Can we call a base class method without creating instance?

Its possible If its a static method.

Its possible by inheriting from that class also.

Its possible from derived classes using base keyword. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend