abstract class vs interface

PHP Abstract and Interface Class

PHP 6 Months 100% Job Assistance Program. for more info... call on 8588829328

Abstract class

Abstraction is a way of hiding information .

In abstraction there should be at least one method which must be declared but not defined.

The class that inherit this abstract class need to define that method.

There must be a abstract keyword that must be return before this class for it to be abstract class.

This class cannot be instantiated . only the class that implement the methods of abstract class can be instantiated.

There can be more than one methods that can left undefined.

Eg i

Defined function b
Can be used as it is

in the above example class a is a abstract class and it contains a abstract method b().
the child class m inherit class a in which abstract method be is defined completely.

Eg ii



The class that is fully abstract is called interface.

Any class that implement this interface must use implements keyword and all the methods that are declared in the class must be defined here. otherwise this class also need to be defined as abstract.

Multiple inheritance is possible only in the case of interface.


in above example there are two interfaces A and B. a class c implements both interfaces and define the methods f1() and f2()
of interfaces A and B respectively. if any of the method of interfaces are left undefined in the class that implements the interface then
it must be defined as abstract.

Latest Trending Technologies