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


PHP Source Code » Class » Method Override »

 

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>


           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Class
» Method Override