Friday, August 7, 2015

Private & Public Member functions of a Class- Part (A)

class Dummy
{
private:int a,b;         // PRIVATE DATA MEMBERS
public: int c,d;          // PUBLIC DATA MEMBERS
private:
void getdata()          // PRIVATE MEMBER FUNCTIONS
{
cout<<"Enter the values";
cin>>a;
cin>>b;
}
void get_publicdata()
{
cout<<"Enter the values";
cin>>c;
cin>>d;
}
void display()          // PUBLIC MEMBER FUNCTIONS
{
cout<<"The value of a is"<<a;
cout<<"The value of b is"<<b;
cout<<"The value of c is"<<c;
cout<<"The value of d is"<<d;
}
};//closure of the class
void main()
{
Dummy D;// class instantiation
D.a=100;       //ERROR
D.b=200;       //ERROR
D.c=300;
D.d=400;
D.get_privatedata();      //ERROR
D.get_publicdata();      //ERROR
D.display();// invoking the public  member function of the class via an Object of the class
}

No comments:

Post a Comment