Using the parent construct : Inheritance « Class « PHP






Using the parent construct

 
<?php
class Cat {
    var $age;

    function Cat($new_age){
        $this->age = $new_age;
    }
    function Birthday(  ){
        $this->age++;
    }
    function Eat(  ){

        echo "Chomp chomp.";
    }
    function Meow(  ){

        echo "Meow.";
    }
}

class MyCat extends Cat {
    function MyCat(  ) {
    }
    function eat(  ) {
        parent::eat(  );
        $this->meow(  );
    }
}
?>
  
  








Related examples in the same category

1.subclass and parent class
2.Three levels of inheritance
3.extends and implement
4.Basic Inheritance
5.Class Inheritance
6.Class Member Binding in PHP
7.Creating a Class That Inherits from Another
8.Define an Executive class that inherits Employee
9.inheritance example
10.Using the extends keyword to define a subclass
11.Example of Inheritance
12.Overriding parent methods
13.Using inheritance to efficiently represent various vehicle types