Interface

  • An interface is similar to a class except that it cannot contain code.
  • An interface can define method names and arguments, but not the contents of the methods.
  • Any classes implementing an interface must implement all methods defined by the interface.
  • A class can implement multiple interfaces.
  • An interface is declared using the "interface" keyword.
  • Interfaces can't maintain Non-abstract methods.

Example 1

snippet
<?php
	interface a
	{
		public function dis1();
	}
	interface b
	{
		public function dis2();
	}

class demo implements a,b
{
	public function dis1()
	{
		echo "method 1...";
	}
	public function dis2()
	{
		echo "method2...";
	}
}
$obj= new demo();
$obj->dis1();
$obj->dis2();

?>

Output:

Interface

Example 2

snippet
<?php
	interface i1
	{
		public function fun1();
	}
	interface i2
	{
		public function fun2();
	}
class cls1 implements i1,i2
{
	function fun1()
	{
		echo "rookienerd";
	}
	function fun2()
	{
		echo "SSSIT";
	}
}
$obj= new cls1();
$obj->fun1();
$obj->fun2();

?>

Output:

Interface
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +