这一章中我们主要讲一下关于类的继承性。
什么是类的继承性?
继承性是面向对象程序设计的重要特性之一,它是指建立一个新的派生类,从一个先前定义的类中继承属性和方法,而且可以重新定义或者加进新的属性和方法以建立类的层次或等级关系。简单地说继承性就是就是通过子类对父类进行功能扩展,继承而产生的类叫做子类,被继承的类叫做父类或超类。
php中类的继承需要注意的地方
1、一个类只能直接从另一个类中继承属性和方法,但一个类可以有多个子类。
2、子类不能继承父类的私有属性和私有方法。
3、在PHP5中类的方法可以被继承,类的构造函数也能被继承。
php中类的继使用关键字"extends"实现多个类的单继承关系,下面我们通过一个实例来演示一下父类和子类之间的层次关系。
首先我们来定义一个Person类作为父类,Person类具有人的基本属性如名字,性别和年龄以及说话和走路等行为。看代码:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment