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 11, 2008
Improving accessibility for motor impaired users
WebDevTips UK
 
May 11, 2008
10 ways to orientate users on your site
WebDevTips UK
 
May 11, 2008
Web Design Clinic - Rros restoration camp 2006
About
 
May 10, 2008
The Moods of Facebook
About
 
May 9, 2008
CSS 1 properties are a great start
About
 
May 9, 2008
Reader Question: How do you get fancy fonts?
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /C#

Virtual Methods & Polymorphism in C# 

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

Synopsis:

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

Class N : D {
public new void foo () {}
}
N n = new N ();n.foo; // calls N's foo ((D)n).foo; // calls D's foo
((B)n).foo(); //calls D's foo

In contrast to both c++ and Java, requiring the override keyword makes it more clear as to what methods are overridden when looking at source code.However, requiring the use of the virtual methods has its pros and cons.

The first pro is the slightly increased execution speed from avoiding virtual methods.The second pro is to make clear what methods are intended to be overridden.However, this pro can also be a con.Compare the default option of leaving out a final modifier in Java Vs leaving out a virtual modifier in C++. The default option in Java may make your program slightly less efficient, but in C++ it may prevent extendibility, albeit unforeseen, by the implementer of the base class.

Pages: firstback1 forwardlast



 
  Sponsors