Inheritance in C++ programming is one of the key feature of OOP. Inheritance allows us to inherit attributes and methods from one class to another class.
#include<iostream.h>
#include<conio.h>
class cls
{
public:
void fun()
{
cout<<"This is fun() function of class cls";
}
};
class cls2:public cls //inheriting class 'cls2' from class 'cls'.
{
public:
void fun2()
{
cout<<"This is fun2() function of class cls2"<<endl;
}
};
void main()
{
cls2 obj; //'obj' is object of class 'cls2'.
obj.fun2(); //calling 'fun2()' function.
obj.fun(); //calling 'fun()' function.
getch();
}
//in Inheritance Child Class accessing Parent Class but Parent Class Can't
//Access Child Class.
//and Child Class Can't access another Child Class which Parent is One Class.