Class method override Demo : Method Override « Class « PHP






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();
?>

           
       








Related examples in the same category

1.Method override for Rectangle class
2.The Method of a Child Class Overriding That of Its Parent
3.Calling an Overridden Method