Advertisement

Thursday 18 April 2013

Difference Between Overloading and Overriding

Overloading:
In Simple words, Same function name but different signature(Parameters)



Ex:

class Maths{

function sum($a, $b) {

$c=$a+$b;
return c; 

}

function sum($a, $b, $c) {           //PARAMETERS DIFFERS

$d=$a+$b+$c;
 return $d;
}


}



Overriding(Polyphormism):
Same Function Name, same signature, different functionality.




Ex:

class Maths{

function sum($a, $b) {

$c=$a+$b;
return c; 

}
 
}

Class Another extends Maths{


function sum($a, $b) {

$c=$a-$b;                            // FUNCTIONALITY DIFFERS
return c; 

}
}

No comments:

Post a Comment