Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to parse the principle of method overwriting and rewriting

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to analyze the method to cover the principle of rewriting, I believe that many inexperienced people do not know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Method overrides the override considerations:

1. You must make sure that the method name is the same and the return value is the same

@ Override: write in front of the method to check whether the override rewriting of the method is valid. This note is not necessary. Even if it is not written, the method override rewriting meets the requirements.

two。 The return value of the subclass method must be [less than or equal to] the return value of the parent method.

3. The modifier of the subclass method must be [greater than or equal to] the modifier of the parent class method

In the inheritance relationship, the access characteristics of parent-child class constructors are as follows: 1. A call to "super ()" is implied by default in the subclass constructor, and it is the first line of the statement in the subclass constructor, so execute the constructor of the parent class before the constructor of the subclass (parent before child)

two。 Subclasses can use super (...) To call the overloaded constructor of the parent class

3.super calls the constructor of the parent class, which must be the first line of the subclass constructor, and cannot call the super construct multiple times in a subclass constructor

This ([...]) Considerations for accessing other constructors of this class:

1. In the constructor, you can use this ([...]) Keyword calls other constructors of this class, but this ([...]) Must be the first line of the constructor, and there can only be one

Both 2.super and this call constructions are required to be the first line of statements and only one in the constructor, so super and this cannot be used at the same time when invoking constructions.

Inherit three characteristics:

1. Single inheritance, a class can only have one direct parent class

two。 Multi-level inheritance, I have a father, my father also has a father, that is, grandfather

3. A parent class can have many children, have a second child, and have many brothers and sisters.

After reading the above, have you mastered how to parse the method and overwrite the implementation principle? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report