OOP : Class : Overriding methods (contents are changed).

Objective

  • override; contents changed
  • overload (very promising in C++,C# and Java), and relaxed in PHP, as $data can take any value parameter

Code

<?php
class base
{
public function base()
{
echo "<br/><font style='font-size:20px; color:red;'>
base class constructor</font>";
}

public function methodA() {
echo "<br/>This is base class methodA()";
}
}
// inheriting a class with extend word
class derived extends base
{
//overriding methodA()
public function methodA()
{
echo "<br/>Class derived methodA is overridden";
}

}
// testing base class directly
$dr1 = new base();
$dr1->methodA();
//testing derived class
$dr = new derived();
$dr->methodA();

?>

Run Time Views