Differences 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.

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;

Namespace Example07
{
Class Program
{
Class Baseclass
{
Public Virtual Void F ()
{
Console. writeline ( " Baseclass. f " );
}
}
Class Deriveclass: baseclass
{
Public Override Void F ()
{
Base . F ();
Console. writeline ( " Deriveclass. f " );
}
Public Void Add ( Int Left, Int Right)
{
Console. writeline ( " Add for INT: {0} " , Left + Right );
}
Public Void Add ( Double Left, Double Right)
{
Console. writeline ( " Add for INT: {0} " , Left + Right );
}
}
Static Void Main ( String [] ARGs)
{
Deriveclass tmpobj = New Deriveclass ();
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

Note:
1. Class Deriveclass: baseclass inherits the parent class
2.Override VoidF () Override the virtual method of the parent class
3.Public VoidAdd (IntLeft,IntRight) andPublic VoidAdd (DoubleLeft,DoubleRight) is the overload relationship.

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.