Tuesday, October 23, 2012

Question 2: Predict the output

                class BaseClass
    {
      public:
        virtual void display()
        {
            std::cout<<"Base Class Virtual Function\n";
        }
    };

    class DeriveClass : public BaseClass
    {
      private:
        virtual void display()
        {
            std::cout<<"Derive Class Virtual Function\n";
        }
    };
    int main()
    {
        BaseClass *obj = new DeriveClass();
        obj->display();
        getch();
    }



    Options:

    a)     Base Class Virtual Function

    b)    Derive Class Virtual Function

    c)     Compilation Error : Unable to access private member function.

    d)    None of the above.


    Answer: b

No comments:

Post a Comment