Computer Science, asked by 2134akshay9, 4 months ago

Can we pass parameters to base class constructor though derived class or derived class constructor? (CO 3)​

Answers

Answered by Tanuj4527
0

Explanation:

nxnxnxnxjxkxkxkxkxlxx

Answered by dreamrob
0

Yes, we can pas_s parameters to base class constructor through derived class or derived class constructor.

Program :

#include<iostream>

using namespace std;

class Base

{

protected :

 int a;

public :

 Base(int n)

 {

  a = n;

  cout<<"Constructor of base class : "<<a<<endl;  

 }

};

class Derived : public Base

{

private :

 int b;

public :

 Derived(int m , int n) : Base(n)

 {

  b = m;

  cout<<"Constructor of derived class : "<<b<<endl;

 }

};

int main()

{

Derived ob(17 , 26);

return 0;

}

Output :

Constructor of base class : 26

Constructor of derived class : 17

Similar questions