Home » C++ Programming » Classes & Objects » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class Base
    {
    int K;
    public:
    void setInt(int num);
    int getInt();
    };
    class Derived : public Base
    {
    int L;
    public:
    void setL(int num);
    int multiply();
    };
    void Base::setInt(int num)
    {
    K = num;
    }
    int Base::getInt()
    {
    return K;
    }
    void Derived::setL(int num)
    {
    L = num;
    }
    int Derived::multiply()
    {
    return L * getInt();
    }
    int main()
    {
    Derived object;
    object.setInt(12);
    object.setL(3);
    cout << object.multiply();
    return 0;
    }
    1. 36
    2. 12
    3. 3
    4. All of above
    5. None of these
Correct Option: A

In this program, We are multiplying the value 12 and 3 by using inheritance.



Your comments will be displayed only after manual approval.