Calling an Overridden Method : Method Override « Class « PHP






Calling an Overridden Method

<html>
<head>
<title>Calling an Overridden Method</title>
</head>
<body>
<?php
class FirstClass{
    var $name = "Joe";
    function FirstClass( $n ) {
        $this->name = $n;
    }
    function sayHello() {
        print "my name is $this->name<br>";
    }
}

class second_class extends FirstClass {
     function sayHello() {
        print "calling method from parent class -- ";
        FirstClass::sayHello();
     }
}

$test = new second_class("sub class");
$test->sayHello();

?>
</body>
</html>

           
       








Related examples in the same category

1.Method override for Rectangle class
2.Class method override Demo
3.The Method of a Child Class Overriding That of Its Parent