Tuesday, October 23, 2012

Question 5: Predict the output.
    class BaseClass
    {
    public:
        virtual void display() = 0;
    };

    void BaseClass::display()
    {
        std::cout<<"Defination of Pure Virtual Function\n";
    }

    class DeriveClass : public BaseClass
    {
    public:
        virtual void display()
        {
            std::cout<<"Defination of Derive Class Function\n";
            BaseClass::display();
        }
    };

    int main()
    {
        BaseClass* obj = new DeriveClass();
        obj->display();
    }



    Options:

    a)     Compilation Error. As pure virtual function has a body which is not allowed.

    b)    Run time crash.

    c)     Defination of Derive Class Function.
         Defination of Pure Virtual Function.

    d)    None of the above.



    Answer: c

No comments:

Post a Comment