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.
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.
Output:
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.
need an explanation for this answer? contact us directly to get an explanation for this answer