Java rewrite

(1) The polymorphism between the parent class and the child class redefines the functions of the parent class. If a method is defined in a subclass with the same name and parameters as its parent class, we say the method is overriding (Overriding). In Java , subclasses can inherit methods from the parent class without rewriting the same methods.

But sometimes the subclass does not want to inherit the method of the parent class intact, but wants to make certain modifications, which requires method rewriting.

Method overriding is also known as method overriding.


    (2) If the method in the subclass has the same method name, return type and parameter list as a method in the parent class, the new method will overwrite the original method.

If you need the original method in the parent class, you can use the super keyword, which refers to the parent class of the current class.


    (3) The access modification authority of the subclass function cannot be less than that of the parent class;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325896046&siteId=291194637