Overloading and rewriting in PHP polygon objects

Source: Internet
Author: User
Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class. The overloaded method is to change the type of the return value. That is, the overloaded return value types can be the same or different.

Overloading (overloading)

A, method overloading is a means for a class to handle different types of data in a uniform manner. Multiple functions with the same name exist at the same time, with different number/types of parameters. Overloaded overloading is a representation of polymorphism in a class.

B, Java's method overloading, is that you can create multiple methods in a class that have the same name but have different parameters and different definitions. The method is called polymorphism by the number of different arguments passed to them and by the type of parameter to determine which method to use.

C, when overloaded, the method name is the same, but the parameter type and number are different, the return value type can be the same or different. The return type cannot be used as a distinguishing criterion for overloaded functions.

2. Rewrite (overriding)

A, the polymorphism between the parent class and the subclass, redefining the function of the parent class. If you define a method in a subclass that has the same name and arguments as its parent class, we say that the method is overridden (overriding). In Java, a subclass can inherit a method from a parent class without rewriting the same method. But sometimes subclasses do not want to inherit the parent class's methods, but want to make some changes, which requires a method of rewriting. Method overrides are also called method overrides.

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

C, subclass functions can not be less than the access adornment permissions of the parent class;

If the parent class member method has exactly the same name, return type, parameter type, and number, except for its internal code, this override is called member method refactoring in Java.

Subclasses can re-adjust the permissions (from stingy to generous), extend or readjust the function of the parent class, and so on, often let the subclass blue, and wins Bluetooth. In the development process, the program developer will use these attributes of the child class. However, from another point of view, you also need to restrict the permissions of the sub-class. Control the permissions of certain methods in the parent class when necessary to prevent abuse of the quilt class.

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.