Home > Backend Development > PHP Tutorial > PHP abstract class inherits abstract class android abstract class method of abstract class

PHP abstract class inherits abstract class android abstract class method of abstract class

WBOY
Release: 2016-07-29 08:48:50
Original
1012 people have browsed it

Reason: uncertainty of the parent class

Why design the abstract class technology?

1.In actual development, we may have such a class, which is the parent class of other classes, but it itself does not need to be instantiated , and its main purpose is to let children Classes are inherited to achieve code reuse and at the same time benefit project designers in designing classes.

2.Keywords:abstract

3.Basic usage:

abstract class class name

{//method

//attribute

function Function name(Parameter list) ; /*abstract modifier

function

function name(parameter list) { echo " This way of writing is wrong!

";//

Because there is an extra method body

} */ } abstract

modified a class, this class is called an abstract class;

abstract

Modify a method, this class is called an abstract method [If it is an abstract method, it cannot have a method body];

4.Notes

:

a

.

Abstract classes can have no abstract methods, and can also have implemented methods (complete functions); b.

Once a method is declared

abstractmethod, the class must be declared as abstract

class , that is, the

abstract class name corresponds to the abstract method; c.If a class inherits an abstract class, it must inherit all of the abstract class

Abstract method, unless it is an abstract class;

Case 1:

abstract class Animal //parent class

{

public $name; protected $price; abstractpublic function cry();

//

There is no method body. This method is mainly for subclasses to implement

} class Dog extends Animal //

subclass

{

public function

cry

()//

subclass inherits parent class method

{echo " Small The dog is barking! The above has introduced PHP abstract classes, including PHP and abstract class content. I hope it will be helpful to friends who are interested in PHP tutorials.

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