The following are several key points of rewriting and polymorphism. I hope everyone can keep it in mind
1. Method rewriting rules:
1. The method names are the same.
2. The parameter list is the same.
3. The return value type is the same or a subclass thereof.
4. Access permissions cannot be stricter than those of the parent class.
2. Abstract method (abstract can also be used for methods):
1. Abstract methods have no method body.
2. Abstract methods must be in Abstract class.
3. Abstract methods must be implemented in subclasses, unless the subclass is an abstract class.
3. Polymorphism:
It is a characteristic that has the ability to express multiple forms. To put it more professionally: the same implementation interface uses different instances to perform different operations.
4. Two methods to achieve polymorphism:
1. Use the parent class as a method parameter to achieve polymorphism.
2. Use the parent class as the method return value to achieve polymorphism.
态. Polymorphism three elements:
## 2 2. Rewriting (sub -category rewriting parent method)3. Father's
Quote Transformation Sub -class instance ## Six.
The benefit of polymorphism: can reduce the amount of code in the category through polymorphism, which can improve the scalability and maintenance of the code.
The above are some key points of rewriting and polymorphism that I have compiled for you. I hope it will be helpful to you in the future.
Related articles:
How to rewrite the padleft method in jsWhat are the inheritance methods in js The specific steps on how to pass two parameters to the JS method in JS onclickThe above is the detailed content of Key points analysis and answers to rewriting and polymorphism. For more information, please follow other related articles on the PHP Chinese website!