Note on overload and override

A few notes on using overload:

  1. You can only pass different parameter forms when using overloads. For example: different parameter types, different number of parameters, different parameter order, of course, several parameter types in the same method must be different. For example can be fun(int, float) but not fun(int, int).
  2. Cannot overload by access rights, exception type and return type
  3. The exception type and number of methods do not affect overloading

A few notes on using override:

  1. The flag of the overridden method must exactly match the flag of the overridden method to achieve the effect of coverage
  2. The exception thrown by the overridden method must be the same as the exception thrown by the overridden method, or a subclass of it
  3. The return value of the overridden method must be the same as the return value of the overridden method
  4. The overridden method cannot be private, otherwise it just defines a new method in its subclass and does not override it

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325027099&siteId=291194637