Custom Search

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:

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

(required)

(required)