Detailed explanation of php abstract class feature examples
Jul 03, 2017 am 09:11 AMCharacteristics of abstract class
1. Classes defined as abstract cannot be instantiated.
2. If at least one method in it is declared abstract, then this class must be declared abstract.
3. A method defined as abstract only declares its calling method (parameters) and cannot define its specific function implementation.
4. When inheriting an abstract class, the subclass must define all abstract methods in the parent class (the access control of these methods must be the same as that in the parent class (or more relaxed).)
demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
5. The subclass can define an optional parameter (that is, it must have a default value), but it is not included in the declaration of the abstract method of the parent class, then There is no conflict between the two statements.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
6. An abstract class does not need an abstract method. On the contrary, a class with an abstract method must be declared as an abstract class.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
7. The order in which abstract classes are defined
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
8. Abstract methods can be staticmethods
1 2 3 4 5 6 7 8 |
|
9. When an abstract class inherits another abstract class, the abstract method does not need to be declared as abstract
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
The above is the detailed content of Detailed explanation of php abstract class feature examples. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
