In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use method overloading in php inheritance. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
The specific analysis is as follows:
Method overload (override) / override-when to use: when the parent class knows that all subclasses need to use a method, but the parent class does not know how to write this method, it needs method overloading. At this point, you can let the subclass override this method.
Popular example-the parent class (animal) knows that its children (cats and dogs) can bark, but they all have different names, so the parent class cannot write this method, and can only let the subclasses (cats and dogs) define it. The code is as follows:
Key points and details of method reloading / coverage (which is a little bit Youkou to read):
1. The method name and parameter list of the method of the subclass is exactly the same as that of the parent method. Such as cry () in the example, you cannot add parameters, change it to cry ($naaa), and so on. Note: the same parameter name is not required here, only that the number of parameters is the same.
2. The so-called overloading or overwriting does not overwrite the methods of the parent class. It can also be understood this way: if the subclass calls the method, if it cannot find the method in its own class, it will go to the parent class to see if there is such a method. This is also the understanding of polymorphism.
3. If a method in a subclass wants to inherit the contents of a method with the same name in the parent class, you can use the parent:: method name or the parent class name:: method name inheritance. Used within a method defined by a subclass.
4. Access permission. The access scope of the subclass > = the access scope of the parent class, that is, if the parent class is protected function cry (), the subclass can only be protected or public.
This is the end of this article on "how to use method overloading in php inheritance". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.