php – interface interview question for fresher & experience programmer

It is very important question for all levels developer. As my experience 7 years in software development , In every interview , They will ask about this question.

Interface  – Interface is nothing , It just using in the place of class .  some example  is given below, so it will be very clear before explain –

 

<?php


interface a
{
public function foo();
}

class b implements a
{
public function foo(){

}
}

?>

Interface contains the only abstract methods  and this methods are going to declare in child class. It means , we can not declare the methods in interface. Every methods should be public so that  we can access this methods in inherited class. We can not create objects of interface , Otherwise it returns fatal error.

 

The use of interfaces becomes very helpful when we work in a team of programmers.

 

In php , multiple  inheritance is not supported . but it can  be achieved by Interface .

There are following example of multiple interface inheritance and will help you great :-

 


<?php
interface a
{
public function foo();
}
interface b
{
public function bar();
}interface c extends a, b
{
public function baz();
}

class d implements c
{
public function foo()
{
}

public function bar()
{
}

public function baz()
{
}
}
?>

 

 

 

Thank you from our team at www.alexawork.com

 

 

 

 

 

 

 

 

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *