heavy load , rewrite , Override , Respectively overload,override,new.

One ,override rewrite , Is to override the methods in the parent class in the child class , The function characteristics of two functions ( Function name , Parameter type and number ) identical . Method used to extend or modify inheritance , attribute , Abstract or virtual implementation of indexer or event . Provides a new implementation of members inherited from the base class , And through override A method that declares overrides is called a base method .
matters needing attention :
1. Overridden base methods must have a override Signature with the same method .
2.override Declaration cannot be changed virtual Method accessibility , And override Methods and virtual Method must have the same level access modifier .
3. out-of-service new,static,virtual Modifier modify override method .
4. Overriding a property declaration must specify exactly the same access modifier as the inherited property , Type and name .
5. Overridden property must be virtual,abstract or override.
6. Non virtual or static methods cannot be overridden .
7. In the parent class abstract, Then the method with the same name of subclass must have override, If there is
virtual method , Subclass methods with the same name are not necessarily override, It could be overload.
8.override There must be a parent-child relationship .

Two ,overload heavy load , Same method name in the same class , Multiple methods with different parameters or return values are method overloads .
matters needing attention :
1. Appears in the same class .
2. Different parameter list or different return type and parameter list , Only return type is different, cannot overload .( The parameter list includes the number and type of parameters )

Three ,overwrite Override , use new realization . Use in subclass new Keyword modifies a defined method with the same name as the parent class , Also known as overlay , Overriding does not change the function of the parent method .

Example :
class Parent { public void F() { Console.WriteLine("Parent.F()"); } public
virtual void G() // Abstract method { Console.WriteLine("Parent.G()"); } public int Add(int
x, int y) { return x + y; } public float Add(float x, float y)
// heavy load (overload)Add function { return x + y; } } class ChildOne:Parent // Subclass one inherits the parent class { new
public void F() // Override (overwrite) Parent function { Console.WriteLine("ChildOne.F()"); }
public override void G() // rewrite (override) Virtual function of parent class , Main implementation polymorphism {
Console.WriteLine("ChildOne.G()"); } } class ChildTwo:Parent // Subclass 2 inherits the parent class { new
public void F() { Console.WriteLine("ChildTwo.F()"); } public override void G()
{ Console.WriteLine("ChildTwo.G()"); } } class Program { static void
Main(string[] args) { Parent childOne = new ChildOne(); Parent childTwo = new
ChildTwo(); // call Parent.F() childOne.F(); childTwo.F(); // Realize polymorphism childOne.G();
childTwo.G(); Parent load = new Parent(); // heavy load (overload)
Console.WriteLine(load.Add(1, 2)); Console.WriteLine(load.Add(3.4f, 4.5f));
Console.Read(); } }

Technology
©2019-2020 Toolsou All rights reserved,
Mybatis Mapping file Mapper.xml in # and $ The difference between ( Essence )2020 year 6 month 26 day C# Class library GUID Help class 415 Status code to background error java Compile time and runtime exceptions in python primitive -- lock LockResult Encapsulation of return result information Map judge key Corresponding value Does the value exist -containsKey() Science fiction comes true !“ Trisomy ” Found out Share has surpassed Ningde Era !LG Chemical confirmation to spin off battery business unit 11-5 Output string at specified position