970_90

Tuesday, 28 May 2013

Difference between Abstract class and Interface in PHP

Difference between Abstract class and Interface in PHP

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


Variable can not be declared
In interface, all methods by default all are abstract methods.




Variable can not be declared
2
The Abstract methods can declare with Access modifiers like public, private, protected.

When implementing in subclass these methods must be defined with the same visibility (Like public, protected and private).
All methods are public in interface.
3
Abstract class can contain variables, concrete methods and constants.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.

No comments:

Post a Comment