Detailed introduction to heavy loading and rewriting of PHP surface objects

Source: Internet
Author: User
This article mainly introduces the reload and rewriting of PHP surface objects. It has good reference value. let's take a look at it below. This article mainly introduces the heavy load and rewriting of PHP surface objects. It has good reference value. let's take a look at it together with the small editor.

Overriding is a manifestation of the polymorphism between the parent class and the child class, and Overloading is a manifestation of the polymorphism in a class. The Overloaded method can change the type of the returned value. That is to say, the type of the returned value of the overload can be the same or different.

Overloading)

A. Method overloading is a means for classes to process different types of data in a unified manner. Multiple functions with the same name exist at the same time and have different parameter numbers/types. Overload Overloading is a manifestation of polymorphism in a class.

B. Java Method overloading means that multiple methods can be created in the class. they have the same name, but have different parameters and different definitions. When calling a method, the number and type of different parameters passed to them are used to determine which method to use. this is polymorphism.

C. during overload, the method name must be the same, but the parameter type and number are different. The return value type can be the same or different. Return types cannot be used as the criteria for distinguishing heavy-duty functions.

2. Overriding)

A. The polymorphism between the parent class and the child class, and the function of the parent class is redefined. If a subclass defines a method with the same name and parameter as its parent class, we say this method is overwritten ). In Java, subclasses can inherit the methods in the parent class without re-writing the same method. But sometimes the subclass does not want to inherit the parent class from the original method, but wants to make some modifications, which requires method rewriting. Method override is also called method override.

B. If the method in the subclass has the same method name, return type, and parameter table as a method in the parent class, the new method overwrites the original method. ** If you need the original method of the parent class, you can use the super keyword, which references the parent class of the current class **.

C. The access modification permission of subclass functions cannot be less than that of the parent class;

If the name, return type, parameter type, and number of the parent class member methods are identical, but their internal code is different, this rewrite method in Java is called member Method refactoring.

Sub-classes can re-adjust the permissions in the parent class method (from small to generous), expand or re-adjust the features of the parent class, and so on, so that the sub-classes are often blue, but better than blue. In the development process, program developers should use these features of sub-classes. However, from another perspective, you also need to restrict the permissions of sub-classes. When necessary, you must control the permissions of some methods in the parent class to prevent abuse of the quilt class.

The above is a detailed introduction to the heavy load and rewriting of PHP Objects. For more information, see PHP Chinese website (www.php1.cn )!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.