Php Object-Oriented Programming-PHP development

Source: Internet
Author: User
Inheritance is one of the important features of object-oriented programming. It refers to the creation of a new derived class that inherits attributes and methods from a previously defined class, in addition, you can redefine or add new attributes and methods to establish a class hierarchy or hierarchical relationship. In simple terms, Inheritance refers to the Function Extension of the parent class through the subclass. The inherited class is called the subclass, And the inherited class is called the parent class or the superclass. This chapter mainly describes the inheritance of classes.


What is the inheritance of classes?

Inheritance is one of the important features of object-oriented programming. It refers to the creation of a new derived class that inherits attributes and methods from a previously defined class, in addition, you can redefine or add new attributes and methods to establish a class hierarchy or hierarchical relationship. In simple terms, Inheritance refers to the Function Extension of the parent class through the subclass. The inherited class is called the subclass, And the inherited class is called the parent class or the superclass.



Notes for class inheritance in php

1. A class can only inherit attributes and methods from another class, but a class can have multiple subclasses.

2. Subclass cannot inherit the private attributes and private methods of the parent class.

3. In PHP5, class methods can be inherited, and class constructors can also be inherited.

In php, the class uses the keyword "extends" to implement the single inheritance relationship between multiple classes. The following uses an instance to demonstrate the hierarchical relationship between the parent class and the subclass.

First, we define a Person class as the parent class. The Person class has the basic attributes of a Person, such as name, gender, age, and behavior such as speaking and walking. Check the Code:

 

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.