output inheritance

output inheritance

#include <iostream>
using namespace std;
class Base{
private:
int i;
protected:
int j;
int get_i()
{ return i;}
public:
int k;
Base()
{i=2; j=4; k=6;}
};
class Der1: public Base{
public:
Der1(){k = 17;}
int getI()
{return get_i();}
};
class Der2: public Der1{
public:
Der2(){k = 15;}
};

int main()
{
Base b;
Der1 d1;
Der2 d2;
//cout << b.i << endl; // private
//cout << b.j << endl; //protected
cout << b.k << endl;
//cout << b.get_i();    //protected
cout << endl;
//cout << d1.i << endl; //private
//cout << d1.j << endl; //protected
cout << d1.k << endl;
//cout << d1.get_i();   //protected
cout << endl;
cout << d1.getI();
cout << endl;
//cout << d2.i << endl; //private
//cout << d2.j << endl; //private
cout << d2.k << endl;
cout << d2.getI();
cout << endl;
return 0;
}

OUTPUT6 , 17, 2 , 15 ,2