Difference Between Private, Public & Protected Class
Private:- Access only With in the class , Not in Derived class & main
Protected:- Access only With in the class & Derived class & but not in main
Public:- Access only With in the class , Derived class & main
Program
#include<iostream.h>
#include<conio.h>
class base
{
private:
int a;
protected :
int b;
public:
int c;
{
a=x;
b=y;
c=z;
}
void display()
{
cout<<"\n a="<<a;
cout<<"\n b="<<b;
cout<<"\n c="<<c;
}
};
{
public:
void display1()
{
//cout<<"\n a="<<a;
cout<<"\n b="<<b;
cout<<"\n c="<<c;
}
};
main()
{
clrscr();
derive d1;
d1.getdata(4,5,6);
cout<<"\n================= BAse(Private can b access)=============";
d1.display();
cout<<"\n==============Derive (Proteceted can b access)=============";
d1.display1();
cout<<"\n==============main (Public can b access)=============";
cout<<"\n c="<<d1.c;
getch();
}
No comments:
Post a Comment