Class Method Override Demo

 
    <?php
class myClass {  var $name = "A";  function myClass($n) {
    $this->name = $n;
  }  function sayHello() {
    echo "HELLO! My name is ".$this->name;
  }}
class childClass extends myClass {  function sayHello() {
    echo "I will not tell you my name.";
  }
}
$object1 = new childClass("a");
$object1 -> sayHello();
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.