21 Program to demonstrate method overriding in PHP

Program:


<?php

   

    class Childs

    {

        function func()

        {

            echo "Child Class <br>";

        }

    }



    class Parents extends Childs

    {



        function func()

        {

            echo "Parent Class <br>";

        }

    }



    $p = new Parents;

    $c = new Childs;



    $c->func();

    $p->func();

?>


Output:


Program to demonstrate method overriding in PHP

Previous
Next Post »