#include <iostream>
using namespace std;
class Base
{
private:
int baseval1;
public:
Base(int val) : baseval1(val){}
int getvalue()
{
return baseval1;
}
void setvalue(int x)
{
baseval1 = x;
cout<<"baseval1 : "<<baseval1<<endl;
}
};
class Derived : public Base
{
public:
Derived(int x) : Base(x){}
void display()
{
//Base b;
int num = getvalue();
cout<<"num : "<<num<<endl;
}
void modify(int x)
{
//Base b;
setvalue(x);
}
};
int main() {
Derived d(10);
d.display();
d.modify(20);
d.display();
return 0;
}
//private datamembers of the base class can be used in derived class by usimng the member function of the base class.
// if we want to directly access the data members in the derived class then we need to make the derived class as friend class in base to access it.
To embed this project on your website, copy the following code and paste it into your website's HTML: