Rewrite and overloaded methods

Rewrite:

Subclasses by the method of rewriting the parent class may be replaced with the behavior of the parent class's own behavior. Rewriting process is necessary to achieve polymorphism.

Overriding methods required to meet the following three points:

      1 "==": methods, the same parameter list.

      2. "≤": return type and declare the exception type, parent subclass or less.

      3. "≥": access to the subclass greater than or equal parent.

 

 

 

 Overload:

Refers to a method of overload classes can be defined in a plurality of the same method name, but different parameters of the method. When invoked, automatically matching method corresponding to the different parameters.

Minefields

      Overloaded method, is actually a completely different approach, it is just the same name!

      The method of constituting the overload condition:

      1. The different meanings: parameter type, parameter number, a different sequence parameter

      2. Only different return value does not constitute a method overloading

      Such as:

1
int a(String str){}与 void a(String str){}

    

      3. Only the different parameter name, does not constitute a method of overloading

      Such as:

1
int a(String str){}与int a(String s){}

    

 

 

 

Guess you like

Origin www.cnblogs.com/cht-/p/11968694.html