#include<iostream.h>
#include<conio.h>
class aa
{
protected:
int n;
public:
int m;
void get()
{
cout<<"enter no";
cin>>m;
}
};
void main()
{
aa obj;
obj.get();
cout<<obj.m; //here as m is public data member therefore it can be used ouside the class
//obj.n; we can't use n outside the class b/c n is the protected data member
getch();
}
//thus concluded that objects can never access private or protected members ( data members or member function ) of the base class.
#include<conio.h>
class aa
{
protected:
int n;
public:
int m;
void get()
{
cout<<"enter no";
cin>>m;
}
};
void main()
{
aa obj;
obj.get();
cout<<obj.m; //here as m is public data member therefore it can be used ouside the class
//obj.n; we can't use n outside the class b/c n is the protected data member
getch();
}
//thus concluded that objects can never access private or protected members ( data members or member function ) of the base class.
0 comments:
Post a Comment