/*C++ program to demonstrate example of private simple inheritance.*/
Ref: Kamthane
#include
using namespace std;
class A
{
private:
int a;
protected:
int x; //can access by the derived class
public:
void setVal(int v)
{
x=v;
}
};
class B:private A
{
public:
void printVal(void)
{
//accessing public member function here //protected data member direct access here
setVal(10);
cout << "value of x: " << x << endl;
}
};
int main()
{
//derived class creation
B objB;
objB.printVal(); return 0;
}
Ref: Kamthane
#include
using namespace std;
class A
{
private:
int a;
protected:
int x; //can access by the derived class
public:
void setVal(int v)
{
x=v;
}
};
class B:private A
{
public:
void printVal(void)
{
//accessing public member function here //protected data member direct access here
setVal(10);
cout << "value of x: " << x << endl;
}
};
int main()
{
//derived class creation
B objB;
objB.printVal(); return 0;
}
No comments:
Post a Comment