PHP program to demonstrate the inheritance of interfaces

Here, we are going to demonstrate the inheritance of interfaces in PHP.
Submitted by Nidhi, on November 20, 2020

Here, we will inherit an interface into another interface using the extends keyword and then implement the derived interface into the class.

Program/Source Code:

The source code to demonstrate the inheritance of interfaces is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

<?php
//PHP program to demonstrate the inheritance of interfaces.
interface Inf1
{
    public function Fun1();
}
interface Inf2 extends Inf1
{
    public function Fun2();
}

class Sample implements Inf2
{
    function Fun1()
    {
        printf("Fun1() called<br>");
    }

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

$obj = new Sample();

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

?>

Output:

Fun1() called
Fun2() called

Explanation:

In the above program, we created two interfaces Inf1, Inf2, and a class Sample. The Inf1 interface contains the declaration of Fun1(), and the Inf2 interface contains the declaration of Fun2().

Here, we inherited the Inf1 interface into Inf2 and then implemented the Inf2 interface into Sample class.

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






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.