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 8, 2008
Meet The Hardy Heron: What's New in Ubuntu 8.04
OReilly Network
 
May 8, 2008
Does Enterprise Development Have to Be Painful? (Part Two)
OReilly Network
 
May 8, 2008
Perl Pragma Primer
WebReference.com
 
May 8, 2008
1 comment
.net
 
May 7, 2008
Poll: Do you check the download speed of the pages you build?
About
 
May 6, 2008
Web Design Firms - 18 New Listings
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /C#

Virtual Methods & Polymorphism in C# 

  Views:    21056
  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