encapsulation

Code to demonstrate the ENCAPSULATION

Create a class with the variables in the private or the public access specifier and introduce minimum of 2 function in the public section. In the main function create an object for the class and call the member function of the class with the help of the object created for the class

class encapsulation

{

Private:int a,int b;

  public:

             int addition(int a,int b);

             void display(int c);

};

int encapsulation::addition(int a,int b)

{

    int c=a+b;

    return c;

}

void encapsulation::display(int c)

{

    cout<<c<<endl;

}

int main()

{

    int a=10;

    int b=10;

     encapsulation e;

     int d=e.addition(a,b);

     e.display(d);

    cout << "Hello world!" << endl;

    return 0;

}

OUTPUT

20

Hello world

Posted on by