Home » C++ Programming » Classes & Objects » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class Base
    {
    protected:
    int K;
    public:
    Base(int num1)
    {
    K = num1;
    }
    ~Base()
    {
    }
    };
    class Derived: public Base
    {
    int L;
    public:
    Derived(int num1, int num2): Base(num2)
    {
    L = num1;
    }
    ~Derived()
    {
    }
    void show()
    {
    cout << K << " " << L << endl;
    }
    };
    int main()
    {
    Derived object(5, 6);
    object.show();
    return 0;
    }
    1. 5
    2. 6
    3. 5 6
    4. 6 5
    5. None of these
Correct Option: D

In this program, We are passing the values and assigning it to K and L and we are printing it.



Your comments will be displayed only after manual approval.