search
Homephp教程php手册PHP中抽象类和抽象方法概念与用法分析,php抽象

PHP中抽象类和抽象方法概念与用法分析,php抽象

本文实例讲述了PHP中抽象类和抽象方法。分享给大家供大家参考,具体如下:

一、抽象关键字 :abstract

抽象就是无法确切的说明,但又有一定的概念或者名称,在PHP中声明一个抽象类或者方法我们需要使用adstract关键字。

二、抽象方法和抽象类的定义

一个类中至少有一个方法是抽象的,我们称之为抽象类。所以如果定义抽象类首先定义抽象方法。

abstract class class1{
  abstract function fun1();
……
}

1、类中至少有一个抽象方法
2、抽象方法不允许有{ }
3、抽象方法前面必须要加abstract

三、抽象类和方法使用规则

抽象类的几个特点:

1、不能被实例化,只能被继承
2、继承的派生类当中要把所有抽象方法重载才能实例化

实例:

<&#63;php
abstract class cl1{
  abstract function fun1();
  abstract function fun2();
}
class cl2 extends cl1{
  function fun1(){
    echo "第一个";
  }
  function fun2(){
    echo "第二个";
  }
}
$c=new cl2();
echo $c->fun2();
&#63;>

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php文件操作总结》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!