adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    using namespace std;
    class BaseClass 
    {
        int i;
        public:
        void setInt(int n);
        int getInt();
    };
    class DerivedClass : public BaseClass
    {
        int j;
        public:
        void setJ(int n);
        int mul();
    };
    void BaseClass::setInt(int n)
    {
        i = n;
    }
    int BaseClass::getInt()
    {
        return i;
    }
    void DerivedClass::setJ(int n)
    {
        j = n;
    }
    int DerivedClass::mul()
    {
        return j * getInt();
    }
    int main()
    {
        DerivedClass ob;
        ob.setInt(10);       
        ob.setJ(4);          
        cout << ob.mul();    
        return 0;
    }

a.

10

b.

4

c.

40

d.

None of the mentioned

Answer: (c).40

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?