Tuesday, October 23, 2012

Question 10: Predict the output.
    class DemoClass
    {
    public:
        DemoClass()
        {
            std::cout<<"\nDefault Constructor.";
        }
        DemoClass(const DemoClass& copy)
        {
            std::cout<<"\nCopy Constructor.";
        }
        DemoClass& operator = (const DemoClass& obj)
        {
            std::cout<<"\nAssignment Operator.";
            return *this;
        }
    };
    int main()
    {
        DemoClass obj, obj1;
        DemoClass newObj = obj;
        obj1 = obj;
    }


    Options:

    a)     Default Constructor.
         Copy Constructor.
         Default Constructor.
         Assignment Operator.

    b)     Default Constructor.
    Default Constructor.
    Copy Constructor.
    Assignment Operator.

    c)    Copy Constructor.
         Default Constructor.
         Default Constructor.
         Assignment Operator.

    d)     None of the above.


    Answer: b

No comments:

Post a Comment