![PHP Final Class](http://www.tutorialpath.com/wp-content/uploads/2019/02/PHP-Final-Class-1024x672.jpg)
Final classes
Inheritance allows for enormous flexibility within a class hierarchy. You can create sub-classes to extend the functionality of a base class, but PHP OOP gives the possibility to create classes that cannot be extended. Such a class is called final class.
A final class is declared by adding the final keyword before the class word.
Example:
![final class Example](http://www.tutorialpath.com/wp-content/uploads/2019/02/final-class-Example.png)
Output:
![final class output](http://www.tutorialpath.com/wp-content/uploads/2019/02/final-class-output.png)
Final methods
A normal method (public or protected) can be overridden in the child class. If you want a method to remain fixed and unchanging, prefix the definition with the final keyword.
A final method cannot be overridden.
Example:
![final method Example](http://www.tutorialpath.com/wp-content/uploads/2019/02/final-method-Example.png)
Output:
![final method output](http://www.tutorialpath.com/wp-content/uploads/2019/02/final-method-output.png)
Use of Final Keyword:
- The Final keyword prevents child classes from overriding and method.
- It means we define a method with final then it prevents us to over ride the method.