Difference between abstract class and interface in php


Abstract Class

Interface Class

Abstract class - method must be declared as abstract. Abstract methods doesn’t have any definition. The sub class (extend class) can have the definition for those abstract method. Interface - all the methods by default are abstract methods only. So one cannot declare variables in interfaces. The sub class (implement class) can have all method definition for those methods.

The Abstract methods can declare with Access modifiers like public, internal, protected. All methods declared in an interface must be public.

Abstract class can contain variables and concrete methods. Interfaces cannot contain variables and concrete methods, but we can possible to define the constants.

An abstract 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.

1 comment: