• Difference between abstract classes and interfaces in PHP OOPS?

    Difference between abstract classes and interfaces in PHP OOPS?

    Silver Member Asked on December 30, 2016 in Php.
    Add Comment
  • 1 Answer(s)

     

    Abstract Class:

    To define a class as Abstract, the keyword abstract is to be used.
    In abstract class at least one method must be abstract.
    we can create object of abstract class.
    abstract classes may not be instantiated.
    The child classes which inherits the property of abstract base class, must define all the methods declared as abstract.
    Any class that contains at least one abstract method must also be abstract.
    If the abstract method is defined as protected, the function implementation must be defined as either protected or public, but not private.
    Abstract class can contain variables and concrete methods.
    A class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class.

    Interfaces:
    In interface all the method must be abstract.
    All methods declared in an interface must be public.
    Interfaces cannot contain variables and concrete methods except constants.
    A class can implement many interfaces and Multiple interface inheritance is possible.
    To extend from an Interface, keyword implements is used.

    Watched  Youtube Video

            

     

    Silver Member Answered on December 30, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.