Java basic study notes _ method rewrite

1. Definition:

The phenomenon that the same method definition appears in the subclass and the method of the parent class.

2. Explanation:

Method rewriting is also called method duplication and coverage.

The method name, parameter list, and return value type are all the same.

3. Matters needing attention:

The private methods of the parent class cannot be overridden.

The access rights of subclass methods cannot be less than that of the parent class methods.

Subclasses cannot throw larger exceptions than the parent class.

4. Use scenarios:

Expand the function of the parent class.

The function of the parent class is obsolete, and the method of the parent class is reimplemented.

Guess you like

Origin blog.csdn.net/qq_43191910/article/details/114763913
Recommended