Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Encapsulation in C++
Bind Function and Data Member
Hitesh Kumar
SITESBAY.COM
Sitesbay.com
Sitesbay.com
Encapsulation in C++
Encapsulation is not C++ concept it is an Object Oriented Programming concept
that binds...
Sitesbay.com
Data Encapsulation Example in C++
Any C++ program where you implement a class with public and private members...
Sitesbay.com
private:
// hidden data from outside world
int total;
};
int main( )
{
Adder a;
a.addNum(10);
a.addNum(20);
a...
Upcoming SlideShare
Loading in …5
×

Encapsulation C++ | Real Life Example of Encapsulation

1,513 views

Published on

Encapsulation C++ - It bind data member and function into single unit. Most popular real life example of encapsulation is capsule.

Published in: Education
  • Be the first to comment

Encapsulation C++ | Real Life Example of Encapsulation

  1. 1. Encapsulation in C++ Bind Function and Data Member Hitesh Kumar SITESBAY.COM Sitesbay.com
  2. 2. Sitesbay.com Encapsulation in C++ Encapsulation is not C++ concept it is an Object Oriented Programming concept that binds together the data and functions. Let’s see encapsulation in c++ Data Hiding is also known as Encapsulation. Encapsulation is the process of combining data and function into a single unit called class. In simple word we can say that encapsulation is the method of combining the data and functions inside a class. Features and Advantages of the concept of Encapsulation:  Maintenance of Application Easier  Improves the Understandability of the Application  Enhanced Security of Application Real Life Example of Encapsulation in C++ Some most popular real life example of encapsulation in c++ are; 1. Capsule – In side capsule all medicine encapsulated together inside capsule. 2. Mobile Phone – Keypad and screen encapsulated together.
  3. 3. Sitesbay.com Data Encapsulation Example in C++ Any C++ program where you implement a class with public and private members is an example of data encapsulation and data abstraction. Consider the following example: #include <iostream> using namespace std; class Adder{ public: // constructor Adder(int i = 0) { total = i; } // interface to outside world void addNum(int number) { total += number; } // interface to outside world int getTotal() { return total; };
  4. 4. Sitesbay.com private: // hidden data from outside world int total; }; int main( ) { Adder a; a.addNum(10); a.addNum(20); a.addNum(30); cout << "Total " << a.getTotal() <<endl; return 0; } When Above code you compile and execute it give below output Output Total 60

×