heavy load , rewrite , Hiding these three concepts is not very clear to many people , I also missed a lot of information and asked the teacher to understand , If you have any shortcomings, please criticize and correct them !

  definition :

 
heavy load : Occurs in the same scope ( For example, in a class ), Define a series of methods with the same name , But the parameter list of the method is different . In this way, different parameters can be passed to decide which one to call . However, different return value types cannot constitute overload .

  rewrite : Occurs on inheritance , Redefining methods in a parent class in a child class , The methods in the subclass are the same as those in the parent . for example : The base class method is declared as virtual( Virtual method ), Used in derived classes
override Declare the override of this method .

  hide : Base class method is not declared ( Default to non virtual method ), Use in derived classes new Declare the hiding of this method .

  Example :

  heavy load :

  

  rewrite :

 

  hide :

  

  understand :

 
Overload must occur in a class , Same function name , Parameter type or number can be different , Return value types can be different . Select the calling method according to the parameters . Overloading is to let classes handle different data in a unified way , In the same class, multiple methods can use the same name, which is called method overload .

  rewrite override Generally used for interface implementation and method rewriting of inherited classes , it is to be noted that :

  1, The flag of the overridden method must match the flag of the overridden method exactly , To achieve the effect of coverage ;

  2, The return value of the overridden method must be the same as that of the overridden method ;

  3, The exception thrown by the overridden method must be the same as the exception thrown by the overridden method , Or its subclass ;

  4, The overridden method cannot be private, Otherwise, only a new method is defined in its subclass , It's not covered .

  5, so to speak ,override It's a very intelligent thing , It can dynamically decide whether to adopt the method of parent class or subclass .

 
Hiding is simply defined methods in the base class , Also needed in derived classes , If the two methods are identical, there will be syntax errors , So use keywords new Hide the methods in the base class , But it works when you want to use it , No grammar conflict .

Technology
©2019-2020 Toolsou All rights reserved,
Summary of artificial intelligence algorithm Golang Array bisection , Array split , Array grouping CCTV :Tiktok A lawsuit shows the attitude and determination of safeguarding rights ( Essence )2020 year 7 month 15 day Wechat applet template Use of [RK3399][Android7.1] Learning notes DRM Driver development ( introduce )fio Use details Mybatis Mapping file Mapper.xml in # and $ The difference between Python realization switch method Spark SQL- programming element-ui+vue-treeselect Verification of drop down box