Home » » Difference between Abstract class and Interface in PHP

Difference between Abstract class and Interface in PHP

Written By 1 on Tuesday, May 28, 2013 | 2:39 AM


S.No
Abstract Class
Interface
1
For abstract class a method must be declared as abstract. At-least one method must be declared as abstract.  

Variable can not be declared
For interface all the methods by default are abstract methods only. 


Variable can not be declared
2
The Abstract methods can declare with Access modifiers like public, internal, protected. When implementing in subclass these methods must be defined with the same visibility (Like public, protected and private).All methods declared in an interface must be public.
3
Abstract class can contain variables and concrete methods.Interfaces cannot contain variables and concrete methods except constants.
4
A class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class.A class can implement many interfaces and Multiple interface inheritance is possible.



 

 


Similarity between abstract and interface classes

1) We can not create object of abstract and interfaces.
2) Abstract method must be there in abstract and interface 
3) We have to defined all the methods which are abstract in base class.

0 Comment:

Post a Comment