Types of inheritance w.r.to Access Specifiers in C++ Part Three
Types of inheritance w.r.to Access Specifiers in C++ Part Three
Private Inheritance
Source code
#include<iostream>
#include<cstdlib>
using namespace std;
class Parent
{
private:
int a;
protected:
int x; //can access by the derived class
public:
void setVal(int v)
{
x=v;
}
};
class Child:private Parent
{
public:
void printVal(void)
{
setVal(10); //accessing public member function here
cout << "value of x: " << x << endl; //protected data member direct access here
}
};
int main()
{
Child objChild; //derived class object
objChild.printVal();
system("pause");
return 0;
}
//////////////////////////////////////////////////////////////////////////////Out Put//////////////////////////////////////////////

Comments
Post a Comment