Home > Backend Development > PHP Tutorial > PHP Learning (Seventeen)--Inherited PHP from entry to proficiency PHP learning website php100

PHP Learning (Seventeen)--Inherited PHP from entry to proficiency PHP learning website php100

WBOY
Release: 2016-07-29 08:53:17
Original
973 people have browsed it

Inheritance

Inheritance is also one of the important features in object-oriented programming. It plays an extremely important role in the object-oriented field. It refers to establishing a new derived class and integrating it from a previously defined class. Data and functions, and new data and functions can be redefined or added, thereby establishing a hierarchical or hierarchical relationship of classes. Through the integration mechanism, existing data types can be used to define new data types. The new data type defined not only has the newly defined members, but also has the old members. The existing class used to derive a new class is called a base class, also called a parent class or super class. A new class derived from an existing class is called a derived class or the like.

Class inheritance application

<code><span><span>class</span> 子类 <span>extends</span> 父类{</span>
}</code>
Copy after login

Access type control

2. Private access modifier private: When a member in a class is defined as private, all members in the same class have access rights, but they are not allowed to be changed by the outside, and subclasses are not allowed to access. ').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); }); The above introduces PHP learning (seventeen) - inheritance, including the content of PHP learning. I hope it will be helpful to friends who are interested in PHP tutorials.
Access control type private protected public (default)
in the same class YES YES Public The access modifier public: Using this modifier, there are no access restrictions on the members of the class, and all external members can access the members of this class.
3. Protected access modifier protected: Members modified as protected have access rights to subclasses of this class and subclasses of subclasses. They can read and write properties and methods, but cannot be accessed by external code. External code of this subclass does not have access to its properties and methods. Overloading parent class methods in subclasses You cannot define functions with the same name in PHP, including methods with the same name that cannot be defined in the same class, so there is no method overloading. However, methods with the same name as the parent class can be defined in the subclass, because the methods of the parent class already exist in the subclass, so the methods inherited from the parent class can be overridden in the subclass. In PHP, the function of calling the overridden method in the parent class is provided in the overloaded method of the subclass. In this way, in the overridden method of the subclass, you can continue to use the methods integrated and overridden from the parent class, and then add some new functions as required. The calling format is to use parent::method name. In the overloaded method of the subclass, the method overridden by it in the parent class is used.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template