Interfaces practice

 <?php

//We Can't make Object of Interface. We can not implement methods in Interface. we can only
//declare methods in Interface. The methods present in Interface must be implemented in Derived class.
//We can not provide Access modifier to methods which is present in Interface.
//We can provide Access modifier to methods while implementing methods in Derived Class.
//We can not declare properties(member variables) as well as can't assign values to properties
//in Interface. Interfaces may not include member variables(properties).
//Access type for interface method must be omitted. We can only give "public" Access modifier to
//functions which is declared in Interface. Because by default, the Access modifier of Methods in
//interface is "public". Access type for interface method must be public.
//Most of the use of interfaces is for Security purposes.
// Only declare like this as below : function function_Name();

interface parent1
{
    function cal($a, $b);
}
interface parent2
{
    function sub($c, $d);
}
class ChildClass implements parent1, parent2
{
    public function cal($a, $b)
    {
        echo $a + $b;
    }
    public function sub($c, $d)
    {
        echo $c - $d;
    }
}
$test = new ChildClass();
$test->cal(30,55);
echo "<br>";
$test->sub(50,30);
// OUTPUT:
// 85
// 20
?>

Comments

Popular posts from this blog

Logical_Operators

SubQuery with EXISTS and NOT EXISTS in PHP

Get Functions