Object-oriented, is the mainstream of today's programming, for research and development personnel, may be object-oriented, some some understanding, but some of the less commonly used may not be particularly clear. Sometimes it's also useful. Here are a few things to know.
First, some knowledge of the final keyword:
1, the final keyword as a method can be inherited by the quilt class. As below:
Class a{ final function operation () { echo ' A '; }} Class B extends a{} $a =new B (); $a->operation ();
Result:a
2, the final keyword as a class is not allowed to inherit, as follows:
<?php Final class a{ final function operation () { echo ' A '; }} Class B extends a{} $a =new B (); $a->operation ();
There will be the following error:
( ! ) Fatal Error:class B may not inherit from final Class (A) in D:\wamp\www\examble\index19.php on line 9
3, the final keyword as a method can not cover the quilt class, that is, the subclass can not have the same method, as follows
Class a{ final function operation () { echo ' a '; }} class B extends a{ function operation () { echo ' a '; }} $a =new B (); $a->operation ();
There will be the following error:
| ( ! ) Fatal Error:cannot Override final Method A::operation () in D:\wamp\www\examble\index19.php on line |
PHP Classes and objects