Answers for "passing the value to base class constructor from derived class c++"

C++
0

passing the value to base class constructor from derived class c++

#include <iostream>
#include<string>

using namespace std;

class Father{
protected:
    int height;
public:
    Father(){
    cout << "constructor of father is called"<<endl;

    }

};
class Mother{
protected:
    string skincolor;
public:
    Mother(){
    cout << "constructor of mother is called"<<endl;

    }

};

class Child : public Father,public Mother{
public:
    Child(int x,string color) : Father(),Mother(){
    height = x;
    skincolor = color;
    cout << "child classs constructor"<<endl;
    }
void display(){
cout << "height is "<<height<<" skin color is "<<skincolor<<endl;
}
};


int main()
{
    Child anil(24,"while");
    anil.display();
    return 0;
}
Posted by: Guest on May-13-2021

Code answers related to "passing the value to base class constructor from derived class c++"

Browse Popular Code Answers by Language