Java method overridden (override) and method overloading (overload)

First, the method of rewriting (the override)

  Rewrite is the name of a member of a subclass method in the parent class reservations, override a member method of realizing content, change the access member methods or change the members of the return value type.

  In succession there is a special overwrite mode, subclass members parent class return value, exactly the same method name, type and number of parameters, the only difference is a method for realizing content, it referred to the weight of this particular embodiment rewritable structure.

  Rewrite condition:

  1. Parameters must be the same, you can modify the method's return value type, but the type of the return value must be compatible
  2. Access methods can not be reduced

Second, the method of overload (overload)

  Method overloading is permitted in the same class with the same name exist more than one method, as long as the number of parameters or different types of methods can

  Heavy Load:

  1. The return type can be different
  2. You can not only change the return type
  3. You can change the access rights

  Constitute overloaded method:

  1. Different types of parameters, configuration reload
  2. Order different parameters, configuration reload
  3. Number of different parameters, configuration reload

 

Guess you like

Origin www.cnblogs.com/noperx/p/11319703.html