PHP

How to demonstrate the inheritance of abstract classes in PHP | PHP programs

How to demonstrate the inheritance of abstract classes in PHP | PHP programs

How to demonstrate the inheritance of abstract classes in PHP | PHP programs

We will inherit an abstract class into another abstract class using the extends keyword and then inherit the second abstract class into a non-abstract class.

<?php

abstract class Abs1
{
    public abstract function Fun1();
}
abstract class Abs2 extends Abs1
{
    public abstract function Fun2();
}

class Sample extends Abs2
{
    function Fun1()
    {
        printf("Fun1() called<br>");
    }

    function Fun2()
    {
        printf("Fun2() called<br>");
    }
}

$obj = new Sample();

$obj->Fun1();
$obj->Fun2();

?>
TutorialsLink Curator

This is an official account managed by the team TutorialsLink Community