Oops Privateinheritance
Oops Privateinheritance
class Base {
private:
int pvt = 1;
protected:
int prot = 2;
public:
int pub = 3;
int getPVT() // function to access private member
{
return pvt;
}
};
class ProtectedDerived : protected Base {
public:
int getProt() // function to access protected member from Base
{
return prot;
}
int main()
{
ProtectedDerived object1;
cout << "Private cannot be accessed." << endl;
cout << "Protected = " << object1.getProt() << endl;
cout << "Public = " << object1.getPub() << endl;
return 0;
}
OUTPUT