1: Why do I need to inherit a class
In order to use a method of this class or to override the method of this class
The inheritance of a class is a method of inheriting the subclass to inherit the parent class.
Benefits of Inheritance: Subclasses can inherit the properties and methods of the parent class and allow methods or new methods to overwrite the parent class
The metaphor in nature is that "evolution" is the way to acquire new traits without affecting the old species.
2: Inherited syntax
Class Boy extends human{
}
3:final class and Final method
The final class cannot be inherited, and the final method cannot be overridden
Example
Class bb{
Final public Function cc () {
Echo ' Hongniu '
}
}
Class GG extends bb{
Public Function cc () {
Echo ' Dongpeng special drink '
}
}
$g = new BB ();
Echo $g;
If written in this way, the error will indicate that if you inherit a class if the property of the method is final, it cannot be inherited and overridden.
If the BB class is preceded by the final keyword then the statement class GG extends bb{} will also error stating if the class declaration
When the final keyword is written, the class cannot be inherited, and all methods of the class cannot be used and inherited.
A summary of the PHP inheritance classes