190. Write a program to access private member of base class indirectly by derived class of member function?

#include<iostream.h>
#include<conio.h>
class base
{
                int i;
public:
                void show()
                                {
                                i=10;
                                cout<<"I = "<<i<<endl;
                                }
};
class derived:private base
{
private:
                int j;
public:
                derived()
                                {
                                j=20;
                                }
                void display()
                                {
                                show();
                                cout<<"J = "<<j<<endl;
                                }
};
void main()
{
                clrscr();
                derived d;
                d.display();
                getch();
}

190

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: