0% found this document useful (0 votes)
14 views7 pages

ENCAPSULATION and Abstraction in C++

C++ notes

Uploaded by

mohdyasaa9639
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views7 pages

ENCAPSULATION and Abstraction in C++

C++ notes

Uploaded by

mohdyasaa9639
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

ENCAPSULATION

The wrapping up of data and information in a single unit. In Object Oriented Programming,
Encapsulation is defined as binding together the data and the functions that manipulate
them.for example, In a company, there are different sections like the accounts section, finance
section, sales section, etc. Now, The finance section handles all the financial transactions and
keeps records of all the data related to finance. Similarly, the sales section handles all the sales-
related activities and keeps records of all the sales.Now there may arise a situation when for
some reason an official from the finance section needs all the data about sales in a particular
month.In this case, he is not allowed to directly access the data of the sales section. He will
first have to contact some other officer in the sales section and then request him to give the
particular data.This is what Encapsulation is. Here the data of the sales section and the
employees that can manipulate them are wrapped under a single name “sales section”.
PROPERTIES
• Two Important property of Encapsulation
• Data Protection: Encapsulation protects the internal state of an object by keeping
its data members private. Access to and modification of these data members is
restricted to the class’s public methods, ensuring controlled and secure data
manipulation.
• Information Hiding: Encapsulation hides the internal implementation details of a
class from external code. Only the public interface of the class is accessible,
providing abstraction and simplifying the usage of the class while allowing the
internal implementation to be modified without impacting external code.
Features of Encapsulation

Below are the features of encapsulation:


• We can not access any function from the class directly. We need an object to access that function that is using
the member variables of that class.
• The function which we are making inside the class must use only member variables, only then it is
called encapsulation.
• If we don’t make a function inside the class which is using the member variable of the class then we don’t
call it encapsulation.
• Encapsulation improves readability, maintainability, and security by grouping data and methods together.
• It helps to control the modification of our data members.
In this example we
wrapped up the data
member and member
function in the single unit.
This is what encapsulation
is.
ABSTRACTION
• Abstraction means displaying only essential information and ignoring the
details. Data abstraction refers to providing only essential information about
the data to the outside world, ignoring unnecessary details or
implementation. For example,The man only knows that pressing the
accelerator will increase the speed of the car or applying brakes will stop the
car but he does not know how on pressing the accelerator the speed is
actually increasing, he does not know about the inner mechanism of the car
or the implementation of the accelerator, brakes, etc in the car. This is what
abstraction is.
Here we are hiding the
information using
private specifier and
showing the essential
information by public
specifier.so , hiding the
background details
from the user and
giving the specific
information only
Abstraction

Public
member

Private
ggggg
Encapsulation
member

You might also like