Q:

PHP program to implement multiple-inheritance using the interface

belongs to collection: PHP Classes & Objects Programs

0

Here, we will implement multiple-inheritance by inheriting a class and an interface into the derived class.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to implement multiple-inheritance using the interface is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

<?php
//PHP program to implement multiple-inheritance 
//using the interface.
class Base
{
    public function Fun1()
    {
        printf("Fun1() called<br>");
    }
}

interface Inf
{
    public function Fun2();
}

class Derived extends Base implements Inf
{
    function Fun2()
    {
        printf("Fun2() called<br>");
    }

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

$obj = new Derived();

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

?>

Output:

Fun1() called
Fun2() called
Fun3() called

Explanation:

In the above program, we created a class Base and an interface Inf and inherited the Base class and Inf interface into the Derived class.

The Base class contains the function Fun1(), and interface Inf contains the declaration of Fun2(). We defined the Fun2() and Fun3() inside the Derived class.

At last, we created an object $obj of Derived class and called functions that will print the appropriate message on the webpage.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Classes & Objects Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP program to demonstrate the inheritance of inte... >>
<< PHP program to implement multiple interfaces in th...