The Method of a Child Class Overriding That of Its Parent : Method Override « Class « PHP






The Method of a Child Class Overriding That of Its Parent

<html>
<head>
<title>The Method of a Child Class Overriding That of Its Parent</title>
</head>
<body>
<?php
class FirstClass{
    var $name = "first class";
    function FirstClass( $n ){
        $this->name = $n;
    }
    function sayHello(){
        print "Hello my name is $this->name<br>";
    }
}

class second_class extends FirstClass {
     function sayHello(){
        print "say hi<br>";
     }
}

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

?>
</body>
</html>


           
       








Related examples in the same category

1.Method override for Rectangle class
2.Class method override Demo
3.Calling an Overridden Method