This sample program demonstrate the use of class inhertinace ,where  class  can use methods and variables of it parent class ( so child class must not have the names of  ( variables and methods ) of any of its parents classes

 

 

 

 

 

 

 

 

 

#include  <iostream>
using namespace std ;

class baseclass {
    int l ;
public :
    void setnum(int m ){l =m ;}
    int getnum(){ return l;}
    int getr(){ return l+  12 ;}
};

    class childclass :public  baseclass {
        int k ;
    public :
        void setk(int y ){k=y;}
        int  getnun(){ return k*getnum();}
        int Getr (){ return k* getr() ;}

    };
    int main (){
        childclass lop ;
         lop.setnum (4);
          lop.setk(6);
          cout<< " first one  lop.getnun()    4*6    ="<<lop.getnun() <<"  = 24 "
              <<  " \n   Second  one    lop.Getr() 6(4+12)  "<<lop.Getr ()<<endl <<endl ;
          return 0 ;

          }