What is Interface?
Posted by Raj
Interfaces:
interface Shape
{
function getShape();
}
class Circle implements Shape{
public function getShape() {
return "This is Shape of the Circle\n";
}
}
class MultiInher {
public function read(Shape $s) {
$shape = $s->getShape();
//
echo $shape;
}
}
$c = new Circle();
$m = new MultiInher();
$m->read($c);
- In interface all the method must be abstract(only define).
- All methods declared in an interface must be public.
- Interfaces cannot contain variables and concrete methods except constants.
- A class can implement many interfaces and Multiple interface inheritance is possible.
- To extend from an Interface, keyword implements is used.
interface Shape
{
function getShape();
}
class Circle implements Shape{
public function getShape() {
return "This is Shape of the Circle\n";
}
}
class MultiInher {
public function read(Shape $s) {
$shape = $s->getShape();
//
echo $shape;
}
}
$c = new Circle();
$m = new MultiInher();
$m->read($c);
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
OOP interview questions and answers,
PHP,
PHP interview questions and answers
.You can leave a response, or trackback from your own site.