what is interface in php? how it is use?
Answer Posted / sanjeev kumar
Interface: Since we all knows that PHP does not support the
multiple inheritance. But don't worry we have an excellent
idea to do the multiple inheritance in php is Interface.
Interface is just like a class using interface keyword and
contains only function declarations(function with no body).
function is defined in the classes where you call it.
Ex:-
interface FirstInterfName{
function Add();
function Sub(10,5);
}
interface SecondInterfName{
function glbfunc1();
function glbfunc2();
}
class ClassName implements FirstInterfName,SecondInterfName
{
fuction Add()
{
$a = 5;
$a = $a + 1;
echo $a;
}
fuction Sub($a,$b)
{
$c = $a -$b;
echo $c;
}
function glbfunc1()
{
Implements here method...............
}
function glbfunc2()
{
Implements here method...............
}
}
| Is This Answer Correct ? | 24 Yes | 7 No |
Post New Answer View All Answers
How is csrf token generated?
Why use static methods php?
What is rest api in php?
What does the scope of variables means?
What are the advantages of indexes in php?
What does $_server mean?
What is the use of $_server and $_env?
What are the string function in php?
What is the use of mysql_fetch_assoc in php?
Write a query to find the 2nd highest salary of an employee from the employee table?
What is abstraction php?
Is php session id unique?
How is it possible to know the number of rows returned in the result set?
How are cookies created?
What are the features and advantages of object-oriented programming in php?