Tuesday, October 23, 2012

Question 15: Predict the output.

    class DemoClass
    {
    public:
        void display()
        {
            std::cout<<"\nDisplay Function 1";
        }
        void display() const
        {
            std::cout<<"\nDisplay Function 2";
        }
    };

    int main()
    {
        DemoClass obj;
        obj.display();
    }


    Options:
    (a) Display Function 1
    (b) Runtime Error
    (c) Compile Time error: error C2535: 'void DemoClass::display(void)' : member function already defined or declared.
    (d) None of the above.


         Answer: a

1 comment:

  1. this happens because the object created here is non const .

    Check this out for more details :
    http://www.geeksforgeeks.org/archives/24724

    ReplyDelete