Overriding properties and Methods
<?php
class Base
{
public $name = "Parent Class";
public function calculation($a, $b)
{
return $a * $b;
}
}
class Derived
{
public $name = "Child Class";
public function calculation($a, $b)
{
return $a + $b;
}
}
$test = new Base();
$test2 = new Derived();
echo $test->name . "<br>";
echo $test2->name . "<br>";
echo $test->calculation(5, 10) . "<br>";
echo $test2->calculation(40, 30);
// OUTPUT:
// Parent Class
// Child Class
// 50
// 70
?>
Comments
Post a Comment