What method overloading and rewrite that? What's the difference?

Rewrite : In the name of the member of a subclass method in the parent class reservations, rewrite content to achieve a method, which changes the method of access, modify return type of parent class return type of a subclass.


Some rules:
rewrite occurred in the subclass inherits the parent class
parameter list must be completely rewritten with the same method
when override the parent class method, modify the method of authority can range from small to large-scale
return type and method of return is rewritten types may vary, but must be a subclass of a parent class return value (JDK1.5 and earlier return to the same type, JDK1.7 and later can be different)
ways to access rights can not be overridden than the parent class access to lower. Such as: parent class is declared as public, then the subclasses override this method can not be declared protected
override the method can not throw checked exceptions and the new ratio is overridden method broader stated exceptions (which can only be thrown out the parent class method throws an exception subclasses)
declared final method can not be overridden
method is declared as static can not be overridden
method is declared as private can not be rewritten

 

Overload : a class method with the same name exist allows more than one type or number of different parameters of these methods

Heavy Load :

  • The same method name
  • Different parameters or a different sequence or a different number of parameters Parameter Type

Rule :
overloaded method parameter list (number or type) are not the same
overloaded methods may be modified return type
method is overloaded access modifiers may modify the
method of modification may be overloaded exception thrown
method can be the same a class is overloaded, or in a subclass
can not be distinguished as to type of return value of a function of a standard heavy-duty

 

Overloading and rewrite the difference between :

  • Range: rewrite scope is between the parent and child classes; overload occurs in a class which is
  • Parameter List: Overloaded must be different; rewrite can not be modified
  • Return Type: overloading may be modified; the same type or a rewritable method returns subclass
  • Throws an exception: heavy load can be modified; rewrite can be reduced or removed, you must not throw new or broader exceptions
  • Access: overloading can be modified; rewrite must not be done more stringent restrictions


 


 

All resources resources are summarized in the public No.


 

 

Guess you like

Origin www.cnblogs.com/ConstXiong/p/11862766.html