Can we pass parameters to base class constructor though derived class or derived class constructor? (CO 3)
Answers
Answered by
0
Explanation:
nxnxnxnxjxkxkxkxkxlxx
Answered by
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
Social Sciences,
2 months ago
Math,
2 months ago
Science,
4 months ago
Math,
4 months ago
Computer Science,
10 months ago
History,
10 months ago