What is the difference between override and overload )?

Source: Internet
Author: User

Override indicates rewriting, which is used to inherit the Implementation of Virtual members in the base class.

Overload indicates overload. It is used to implement different parameters (including different types or numbers) of methods with the same name in the same class.

Example:

 
UsingSystem;
 
UsingSystem. Collections. Generic;
 
UsingSystem. text;
 
 
 
NamespaceExample07
 
{
 
ClassProgram
 
{
 
ClassBaseclass
 
{
 
Public Virtual VoidF ()
 
{
Console. writeline ("Baseclass. F");
 
}
 
}
 
ClassDeriveclass: baseclass
 
{
 
Public Override VoidF ()
 
{
 
Base. F ();
 
Console. writeline ("Deriveclass. F");
 
}
 
Public VoidAdd (IntLeft,IntRight)
 
{
Console. writeline ("Add for INT: {0 }", Left + right );
 
}
 
Public VoidAdd (DoubleLeft,DoubleRight)
 
{
 
Console. writeline ("Add for INT: {0 }", Left + right );
 
}
 
}
 
Static VoidMain (String[] ARGs)
 
{
 
Deriveclass tmpobj =NewDeriveclass ();
 
Tmpobj. F ();
Tmpobj. Add (1, 2 );
 
Tmpobj. Add (1.1, 2.2 );
 
 
 
Console. Readline ();
 
}
 
}
 
}

Result:
Baseclass. f
Deriveclass. f
Add for INT: 3
Add for INT: 3.3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.