Home » C++ Programming » Classes & Objects » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class BaseClass
    {
    int A;
    public:
    void setA(int num1)
    {
    A = num1;
    }
    void showA()
    {
    cout << A <<" ";
    }
    };
    class DerivedClass : private BaseClass
    {
    int B;
    public:
    void setAB(int num1, int num2)
    {
    setA(num1);
    B = num2;
    }
    void showAB()
    {
    showA();
    cout << B << '\n';
    }
    };
    int main()
    {
    DerivedClass object;
    object.setAB(15, 25);
    object.showAB();
    return 0;
    }
    1. 15
    2. 25
    3. 25 15
    4. 15 25
    5. None of these
Correct Option: D

In this program, We are passing the values from the main class and printing it on the inherited classes.



Your comments will be displayed only after manual approval.