Monday, April 5, 2021

initilization list in constructor (OOP) (28)

 #include<iostream>

using namespace std;

class base

{

int a;

public:

base(int x)

{

a=x;

}

void displayb()

{

cout<<"the value of a is:"<<a<<endl;

}

};

class drived:public base

{

int b;

public:

drived(int x,int y):base(x),b(y)//initilization list in constructor

{

cout<<"base constructor initilized:"<<endl;

}

void displayd()

{

cout<<"the value of b is:"<<b<<endl;

}

};

int main()

{

drived obj(10,20);

obj.displayb();

obj.displayd();

}

No comments:

Post a Comment