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.