sponsor

sponsor

Slider

Recent Tube

Business

Technology

Life & style

Games

Sports

Fashion

» » Encapsulation

C++ Programming - Encapsulation

                   

Introduction for Data Encapsulation

Data Encapsulation का इस्तेमाल हर program में किया जा सकता है | OOP में ये काफी महत्वपूर्ण feature है |
Data Encapsulation में Object के methods और data को एक ही जगह पर मतलब एक ही class पर store करके रखा जाता है |
Data Encapsulation में class के data members और member function को एक ही class में define किये जाते है | Data Encapsulation ये Data Abstraction का भी एक अच्छा उदाहरण है |
ये object की सारी information एक ही जगह पर bind करके रखी जाती है |
Source Code :
#include <iostream.h>
using namespace std;

class A{
    int a, b;

public:
    A(){
    cout<<"Enter two Numbers"<<endl;
    cin>>a>>b;
}
    void display(){
    cout<<"Addition of "<<a<<" and "<<b<<" is "<<a+b<<endl;
    cout<<"Subtraction of "<<a<<" and "<<b<<" is "<<a-b<<endl;
    cout<<"Multiplication of "<<a<<" and "<<b<<" is "<<a*b<<endl;
    cout<<"Division "<<a<<" and "<<b<<" is "<<a/b<<endl;
}
};
int main(){

A obj;
obj.display();
return 0;
}
Output : Enter two Numbers 12 6 Addition of 12 and 6 is 18 Subtraction of 12 and 6 is 6 Multiplication of 12 and 6 is 72 Division 12 and 6 is 2

«
Next
Newer Post
»
Previous
Older Post

No comments:

Leave a Reply