Overloading Java, rewriting and reconstruction of difference

A heavy-duty

  1. Overload concepts: a class in the same method with the same name exist to allow more than one, as long as the type or number of different parameters to these methods.

  2. Overloading rules:

You must have different parameter list.

You can have different return types, as long as the list of different parameters on it.

You can have different access modifiers.

You can throw different exceptions.

Second, rewrite

  1. :( rewrite the concept of coverage can also be called) is retained in the name of the member of a subclass method in the parent class, overriding implementation of the contents of a method, which change the storage permission member methods, or change the members of the return value Types of

  2. Rewrite rules:

Parameter list must be exactly the same as the method is overridden, otherwise it could not be called to rewrite but overloading.

Restricted access modifier must be greater than the access modifier is rewritten method (public> protected> default> private).

Overriding methods must not throw new abnormalities or abnormal ratio is overridden method stated broader examination type. For example: a parent class affirms a checked exception IOException, rewriting this method is you can not throw Exception, IOException subclass can only throw an exception, you can throw an unchecked exception.

Third, reconstruction: a special way is rewritten, the return value of the method subclass members parent class, exactly the same method name, type and number of parameters, the only difference is a method for realizing content, this particular rewritable approach is called remodeling.

Guess you like

Origin www.cnblogs.com/Water2Wine/p/12640323.html