Method Overriding in PHP
In this tutorial, we will learn about Method Overriding in PHP. In concept function overriding we can define a method with the same name and number of arguments in both Parent and Child class. It means the method of child class will override the functionality of the method in the Parent class. The main motive of overriding is to change the behaviour of the parent class method in the child class.
If you don't know about Parent and Child class Please follow our tutorial on Inheritance. Click here to learn Inheritance.
To understand it please check out the following Example Program.
<?php
class Master{
function show(){
echo "This is show method in Master class<br>";
}
}
class Student extends Master{
function show(){
echo "This is show method in Student class<br>";
}
}
$obj = new Master;
$obj->show();
$obj = new Student;
$obj->show();
?>
Spread the love:
Please share this page on social media with your friends..
![]() |
![]() |
![]() |