Final method ad final class

Final method ad final class

Final method
- it is used to prevent the child class to re-implement the function in parent class
- If derived class try to re-implent the final method, php will give error to the user.

Example:

class Base{
final public function test() {
echo “From the base class”;
}
}

In the above example function test is prefixed by final. SO it can’t be overrided by the child class

final class
- If the class is defined with prefix `final`, then it can’t be inherited

Example:

final class Base{
public function test() {
echo “From the base class”;
}
}

In the above example class Base is prefixed by final, so it can’t be inherited. If anyother class try to inherit the above class, php will give the error.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.