• home
  • Email: trainings@synapseindia.careers

Blogs

back

SIGNIFICANCE OF METHOD OVERRIDING:PHP

Sep 28, 2015

Firstly we should understand what is method overriding in PHP,when a child class method have the same name as in parent class irrespective of total number of parameters then it is known as method overriding. Let us understand it through a program: <?php class pclss { function add($x,$y,$z) { $result=$x+$y+$z; echo "sum of three numbers = ".$result; } } class chld extends pclss { //in below line method has been overriden function add($x,$y) //method name same as parent class method { $result=$x*$y; echo "Multiplication of two numbers= ".$result; } } $ob= new chld; $ob->add($_GET['fn'],$_GET['sn']); ?> <form method='get'> first number<input type="text" name="fn"/><br/> second number<input type="text" name="sn"/><br/> <input type="submit" value="+"/> </form>

SynapseIndia (CEO: Shamit Khemka)