4
Reply

what diff b\w abstract and interface? when will go for abstract& interface

sainath reddy

sainath reddy

14y
6.4k
0
Reply

    Abstract Class:

    1. Abstract Class Can contain Abstract Methods and Non-
    Abstract Methods.

    2. When a Non-Abstract Class is Inherited from an Abstract
    Class, the Non-Abstract Class should provide all the
    implementations for the inherited Abstract Method.

    Interface:

    1. Interface is nothing but Pure Abstract Class ie
    Interface can contain only the function declaration.

    2. All the members of the interface are Public by Default
    and you cannot provide any access modifiers.

    3. When a class is inherited from the interface, the
    inherited class should provide actual implementations for
    the inherited members.

    Abstract and interface both are similar
    but some difference

    When there is a need to inheritance then abstract class should be used.
    And When there is need to common functionality implementation by more then one class then Interfaces should be used.

    Abstract class contains pure virtual function and must/can be inherited by the derived class to implement inheritance.
    Where as Interface contains only definition of the functions and must/can be implemented by any other class.