OOPS in PHP 5 Tutorial - Function Overriding
This article will guide you through the Function Overriding which forms the common feature of OOPS. In Object Oriented Programming Function Overriding refers the base class and the child class methods with same name, signature and access specifier.
Example - Function Overriding
< ? class Person { function calculateAge($dob) { echo "calculateAge called of Person Classn"; } } class Customer extends Person { function calculateAge($dob) { echo "calculateAge called of Customer Classn"; } } $c1 = new Customer(); $p1 = new Person(); $c1->calculateAge("something"); $p1->calculateAge("something More"); ?>
Output:
calculateAge called of Customer Class
calculateAge called of Person Class
Explanation:
- Here i am declaring two class Person and Customer
- Customer class is extending the Person class
- Both the class has calculateAge() method and when we try the method individual class method gets called
Similar Posts
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.


Comments
No comments yet.
Leave a comment