iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 15, 2008
Reader Question - Would you host your client's work on your website?
About
 
May 15, 2008
How to Create an Ajax Autocomplete Text Field: Part 6
WebReference.com
 
May 14, 2008
Poll: Are the browser safe colors still needed?
About
 
May 14, 2008
Google Doctype launched
About
 
May 14, 2008
Web Editor Reviews - 6 New Reviews
About
 
May 14, 2008
Build Beautiful Buttons in Photoshop, Part I
SitePoint
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /C#

Virtual Methods & Polymorphism in C# 

  Views:    21351
  Votes:    6
by Pawan Bangar 9/25/04 Rating: 

Synopsis:

Virtual methods allow object oriented languages to express polymorphism.
Pages: firstback2 forwardlast
The Article

Virtual methods allow object oriented languages to express polymorphism.This means that a derived class can write a method with the same signature as a method in its base class, and the base class will call the derived class's method.By default in java, all methods are virtual. In C# like C++, the virtual keyword is needed to specify that a method should override a method (or implementaion an abstract method) of its base class.

Class B {
public virtual void foo () {}

}
ClassD : B {
public override void foo () {}
}
 


Attemting to override a non-virtual method will results in a compile-time error unless the "new" keyword is added to the declaration, indicating the method is intentionally hiding the base clas's method.

Pages: firstback2 forwardlast



 
  Sponsors