Class contains pure virtual function, then it is termed Abstract Class

Q.   If a class contains pure virtual function, then it is termed as____________________ .
- Published on 19 Oct 15

a. Virtual class
b. Sealed class
c. Pure Local class
d. Abstract Class

ANSWER: Abstract Class
 

    Discussion

  • Brijesh   -Posted on 06 Oct 15
    If a class contains pure virtual function, then it is termed as abstract class.
    Abstract classes are used to provide an Interface for its sub classes and it must have pure virtual function.
    Example:
    class BaseClass //Abstract base class
    {
    public:
    virtual void show() = 0; //Pure Virtual Function
    };

    class Derived:public BaseClass
    {
    public:
    void show()
    {
    cout << "Implementation of Pure Virtual Function in Derived class\n";
    }
    };

    int main()
    {

    BaseClass *b;
    Derived obj;
    b = &obj;
    b->show();
    }

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)