Inheritance and Mode of Inheritance in C++
Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
// Inheritance in CPP
#include<iostream>
using namespace std;
class Base
{
private:
void a_private()
{
cout<<"Private method";
}
protected:
void a_protected()
{
cout<<"Protected method";
}
public:
void a_public()
{
cout<<"Public method";
}
};
class Derived: public Base // is A Relation
{
private:
protected:
public:
void abc()
{
a_protected();
}
};
int main()
{
system("cls");
Derived D;
D.a_public();
D.abc();
return 0;
}Program 2
// Inheritance in CPP
#include<iostream>
using namespace std;
class Base
{
public:
int a_pub=100;
private:
int a_pri=300;
protected:
int a_pro=500;
};
class Derived:protected Base
{
};
int main()
{
system("cls");
Derived D;
return 0;
} Did we exceed your expectations?
If Yes, share your valuable feedback on Google

