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


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Virtual and Override Keywords

Posted By:Shashi Ray       Posted Date: February 28, 2009    Points: 25    Category: C#    URL: http://www.dotnetspark.com  
 

Virtual and Override Keywords

 

If you have a method in a base class that you want to allow derived classes to override, you must declare it as virtual. This means that a method of the same name and argument signature in a derived class will be called rather than the one in the base class. Then, you must declare the method in the derived class using the override keyword.

 

If you use the override keyword in a derived class without declaring the base class's method as virtual the compiler will flag this as an error. If you create a method in a derived class that is identical in name and argument signature to one in the base class and do not declare it as overload, this also is an error. If you create a method in the derived class and do not declare it as override and also do not declare the base class's method as virtual the code will compile with a warning but will work correctly, with the derived class's method called as you intended.

 

Shashi Ray

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

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