Data Abstraction

Object Oriented Programming in C++
Central University Of Kashmir
Data Abstraction in
C++
Presented by : Peerzada Sameem Makhdoomi
Enrollment no. 2124CUKmr09
• Data Abstraction is a programming technique that depends on the separation of
the interface and implementation details of the program.
• Data Abstraction is a process of providing only the essential details to the
outside world and hiding the internal details i.e., representing only the essential
details in the program.
• let's take a real life example of AC, which can be turned ON or OFF, change the
temperature, change the mode, and other external components such as fan,
swing. But, we don't know the internal details of the AC, i.e., how it works
internally. Thus, we can say that AC separates the implementation details from
the external interface.
• C++ provides a great level of abstraction. For example, pow() function is used to
calculate the power of a number without knowing the algorithm the function
follows.
What is data abstraction ?
Data Abstraction can be achievedin two ways:
 Abstraction using classes
 Abstraction in header files.
 Abstraction using classes:- An abstraction can be achieved using
classes. A class is used to group all the data members and member functions
into a single unit by using the access specifiers. A class has the responsibility
to determine which data member is to be visible outside and which is not.
 Abstraction in header files:- An another type of abstraction is header
file. For example, pow() function available is used to calculate the power of
a number without actually knowing which algorithm function uses to
calculate the power. Thus, we can say that header files hides all the
implementation details from the user.
Access Specifiers Implement Abstraction:
In C++, we use access labels to define the abstract interface to the class.
A class may contain zero or more access labels
o Members defined with a public label are accessible to all parts of the program.
The data-abstraction view of a type is defined by its public members.
o Members defined with a private label are not accessible to code that uses the
class. The private sections hide the implementation from code that uses the type
Advantages of Data Abstraction:
 Helps the user to avoid writing the low level code
 Avoids code duplication and increases reusability.
 Can change internal implementation of class independently without affecting
the user.
 Helps to increase security of an application or program as only important
details are provided to the user.
i. Abstraction separates code into interface and implementation. So
while designing your component, you must keep interface
independent of the implementation so that if you change
underlying implementation then interface would remain intact.
ii. In this case whatever programs are using these interfaces, they
would not be impacted and would just need a recompilation with
the latest implementation.
Designing Strategy:
Let's see a simple example of abstraction in header files.
// Program to calculate the power of any number.
#include <iostream>
#include<math.h>
using namespace std;
int main( ) {
int number , result , power = 3;
cout<<“Enter any number:”<<endl; // for example 4
cin>>number;
result = pow (number , power); // pow (number , power) is the power function
cout << "Cube of the number is : "<<result<< endl;
return 0;
}
Output:
Cube of the number is : //64
In the above example, pow() function is used to calculate 4 raised to the power 3. The pow()
function is present in the math.h header file in which all the implementation details of
the pow() function is hidden.
#include <iostream>
using namespace std;
class implementAbstraction{
private:
int a, b;
public:
// method to set values of
// private members
void set(int x, int y)
{ a = x;
b = y; }
void display() {
cout<<"a = " <<a << endl;
cout<<"b = " << b << endl;
}
};
int main()
{
implementAbstraction obj;
obj.set(10, 20);
obj.display();
return 0;
}
example:
Output:
a = 10 b = 20
 You can see in the above program we are not allowed
to access the variables a and b directly, however one
can call the function set() to set the values in a and b
and the function display() to display the values of a
and b.
References:
 https://www.tutorialspoint.com/cplusplus/cpp_data_abstraction.htm#:~:text=Data%20abstract
ion%20refers%20to%20providing,program%20without%20presenting%20the%20details.
 https://www.geeksforgeeks.org/abstraction-in-c++/
 https://www.javatpoint.com/data-abstraction-in-cpp
Thankyou :)
1 de 11

Recomendados

Operator overloading and type conversion in cpp por
Operator overloading and type conversion in cppOperator overloading and type conversion in cpp
Operator overloading and type conversion in cpprajshreemuthiah
498 visualizações18 slides
Static Data Members and Member Functions por
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
3.8K visualizações9 slides
Introduction Of C++ por
Introduction Of C++Introduction Of C++
Introduction Of C++Sangharsh agarwal
6K visualizações34 slides
[OOP - Lec 07] Access Specifiers por
[OOP - Lec 07] Access Specifiers[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access SpecifiersMuhammad Hammad Waseem
3.9K visualizações9 slides
Type casting por
Type castingType casting
Type castingsimarsimmygrewal
3.7K visualizações6 slides
C# classes objects por
C#  classes objectsC#  classes objects
C# classes objectsDr.Neeraj Kumar Pandey
2.9K visualizações25 slides

Mais conteúdo relacionado

Mais procurados

Constructors and Destructor in C++ por
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++International Institute of Information Technology (I²IT)
445 visualizações17 slides
Functions in c por
Functions in cFunctions in c
Functions in csunila tharagaturi
1.5K visualizações42 slides
Inheritance in c++ por
Inheritance in c++Inheritance in c++
Inheritance in c++Vineeta Garg
28.6K visualizações26 slides
INLINE FUNCTION IN C++ por
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++Vraj Patel
6K visualizações13 slides
Type casting in java por
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
2.4K visualizações10 slides
class and objects por
class and objectsclass and objects
class and objectsPayel Guria
22.8K visualizações15 slides

Mais procurados(20)

Functions in c por sunila tharagaturi
Functions in cFunctions in c
Functions in c
sunila tharagaturi1.5K visualizações
Inheritance in c++ por Vineeta Garg
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg28.6K visualizações
INLINE FUNCTION IN C++ por Vraj Patel
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel6K visualizações
Type casting in java por Farooq Baloch
Type casting in javaType casting in java
Type casting in java
Farooq Baloch2.4K visualizações
class and objects por Payel Guria
class and objectsclass and objects
class and objects
Payel Guria22.8K visualizações
Datatype in c++ unit 3 -topic 2 por MOHIT TOMAR
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR2.4K visualizações
Object Oriented Programming Using C++ por Muhammad Waqas
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
Muhammad Waqas11.1K visualizações
Constructor ppt por Vinod Kumar
Constructor pptConstructor ppt
Constructor ppt
Vinod Kumar25.4K visualizações
Inheritance in c++ por Vishal Patil
Inheritance in c++Inheritance in c++
Inheritance in c++
Vishal Patil1.8K visualizações
Java abstract class & abstract methods por Shubham Dwivedi
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi7.5K visualizações
Constructor and Types of Constructors por Dhrumil Panchal
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal2.8K visualizações
Functions in c++ por Rokonuzzaman Rony
Functions in c++Functions in c++
Functions in c++
Rokonuzzaman Rony1.3K visualizações
Oop c++class(final).ppt por Alok Kumar
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar51.9K visualizações
Pointers in c++ por Vineeta Garg
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg25.2K visualizações
Constructor and Destructors in C++ por sandeep54552
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
sandeep54552207 visualizações
Constructors in C++ por RubaNagarajan
Constructors in C++Constructors in C++
Constructors in C++
RubaNagarajan503 visualizações
Templates in C++ por Tech_MX
Templates in C++Templates in C++
Templates in C++
Tech_MX18.1K visualizações
Object oriented programming with python por Arslan Arshad
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with python
Arslan Arshad3.8K visualizações

Similar a Data Abstraction

DATA ABSTRACTION.pptx por
DATA ABSTRACTION.pptxDATA ABSTRACTION.pptx
DATA ABSTRACTION.pptxManavSharma694627
12 visualizações14 slides
Data structure week 1 por
Data structure week 1Data structure week 1
Data structure week 1karmuhtam
275 visualizações30 slides
SRAVANByCPP por
SRAVANByCPPSRAVANByCPP
SRAVANByCPPaptechsravan
279 visualizações147 slides
Programming in c++ por
Programming in c++Programming in c++
Programming in c++sujathavvv
21 visualizações12 slides
Programming in c++ por
Programming in c++Programming in c++
Programming in c++MalarMohana
13 visualizações12 slides
Unit 1 por
Unit  1Unit  1
Unit 1donny101
221 visualizações48 slides

Similar a Data Abstraction(20)

DATA ABSTRACTION.pptx por ManavSharma694627
DATA ABSTRACTION.pptxDATA ABSTRACTION.pptx
DATA ABSTRACTION.pptx
ManavSharma69462712 visualizações
Data structure week 1 por karmuhtam
Data structure week 1Data structure week 1
Data structure week 1
karmuhtam275 visualizações
SRAVANByCPP por aptechsravan
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
aptechsravan279 visualizações
Programming in c++ por sujathavvv
Programming in c++Programming in c++
Programming in c++
sujathavvv21 visualizações
Programming in c++ por MalarMohana
Programming in c++Programming in c++
Programming in c++
MalarMohana13 visualizações
Unit 1 por donny101
Unit  1Unit  1
Unit 1
donny101221 visualizações
Interoduction to c++ por Amresh Raj
Interoduction to c++Interoduction to c++
Interoduction to c++
Amresh Raj275 visualizações
C++ Version 2 por JIGAR MAKHIJA
C++  Version 2C++  Version 2
C++ Version 2
JIGAR MAKHIJA67 visualizações
C++ Constructs.pptx por LakshyaChauhan21
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
LakshyaChauhan2111 visualizações
PRINCE PRESENTATION(1).pptx por SajalKesharwani2
PRINCE PRESENTATION(1).pptxPRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptx
SajalKesharwani211 visualizações
c++ referesher 1.pdf por AnkurSingh656748
c++ referesher 1.pdfc++ referesher 1.pdf
c++ referesher 1.pdf
AnkurSingh65674815 visualizações
C++ Programming por Rounak Samdadia
C++ ProgrammingC++ Programming
C++ Programming
Rounak Samdadia1.1K visualizações
Principal of objected oriented programming por Rokonuzzaman Rony
Principal of objected oriented programming Principal of objected oriented programming
Principal of objected oriented programming
Rokonuzzaman Rony570 visualizações
Principles of object oriented programing por Ahammed Alamin
Principles of object oriented programingPrinciples of object oriented programing
Principles of object oriented programing
Ahammed Alamin239 visualizações
Oop concept in c++ by MUhammed Thanveer Melayi por Muhammed Thanveer M
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
Muhammed Thanveer M654 visualizações
Object oriented programming 7 first steps in oop using c++ por Vaibhav Khanna
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++
Vaibhav Khanna130 visualizações
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad por Faisal Shehzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Faisal Shehzad239 visualizações
C Programming Unit-1 por Vikram Nandini
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini494 visualizações

Mais de Sameem Makhdoomi

Google's Employer Branding Strategy.pdf por
Google's Employer Branding Strategy.pdfGoogle's Employer Branding Strategy.pdf
Google's Employer Branding Strategy.pdfSameem Makhdoomi
1K visualizações10 slides
QUIZLET por
QUIZLETQUIZLET
QUIZLETSameem Makhdoomi
30 visualizações12 slides
Linear Differential Equation and Equations Reducible to Linear Form por
Linear Differential Equation and Equations Reducible to Linear FormLinear Differential Equation and Equations Reducible to Linear Form
Linear Differential Equation and Equations Reducible to Linear FormSameem Makhdoomi
271 visualizações21 slides
Huffman Algorithm/coding tree - Data Structures por
Huffman Algorithm/coding tree - Data Structures Huffman Algorithm/coding tree - Data Structures
Huffman Algorithm/coding tree - Data Structures Sameem Makhdoomi
17 visualizações25 slides
Coulomb's Law por
Coulomb's LawCoulomb's Law
Coulomb's LawSameem Makhdoomi
55 visualizações46 slides
Genetic Disorders por
Genetic DisordersGenetic Disorders
Genetic DisordersSameem Makhdoomi
53 visualizações13 slides

Mais de Sameem Makhdoomi(13)

Google's Employer Branding Strategy.pdf por Sameem Makhdoomi
Google's Employer Branding Strategy.pdfGoogle's Employer Branding Strategy.pdf
Google's Employer Branding Strategy.pdf
Sameem Makhdoomi1K visualizações
Linear Differential Equation and Equations Reducible to Linear Form por Sameem Makhdoomi
Linear Differential Equation and Equations Reducible to Linear FormLinear Differential Equation and Equations Reducible to Linear Form
Linear Differential Equation and Equations Reducible to Linear Form
Sameem Makhdoomi271 visualizações
Huffman Algorithm/coding tree - Data Structures por Sameem Makhdoomi
Huffman Algorithm/coding tree - Data Structures Huffman Algorithm/coding tree - Data Structures
Huffman Algorithm/coding tree - Data Structures
Sameem Makhdoomi17 visualizações
Coulomb's Law por Sameem Makhdoomi
Coulomb's LawCoulomb's Law
Coulomb's Law
Sameem Makhdoomi55 visualizações
Genetic Disorders por Sameem Makhdoomi
Genetic DisordersGenetic Disorders
Genetic Disorders
Sameem Makhdoomi53 visualizações
Application of Network Theorem in AC Circuit. Resonance in series and paralle... por Sameem Makhdoomi
Application of Network Theorem in AC Circuit. Resonance in series and paralle...Application of Network Theorem in AC Circuit. Resonance in series and paralle...
Application of Network Theorem in AC Circuit. Resonance in series and paralle...
Sameem Makhdoomi80 visualizações
Body language and use of voice during the presentation por Sameem Makhdoomi
 Body language and use of voice during the presentation Body language and use of voice during the presentation
Body language and use of voice during the presentation
Sameem Makhdoomi117 visualizações
CRIMINOLOGY por Sameem Makhdoomi
CRIMINOLOGYCRIMINOLOGY
CRIMINOLOGY
Sameem Makhdoomi15 visualizações
Data mining por Sameem Makhdoomi
Data miningData mining
Data mining
Sameem Makhdoomi15 visualizações
Energy levels of the system and transitions por Sameem Makhdoomi
Energy levels of the system and transitionsEnergy levels of the system and transitions
Energy levels of the system and transitions
Sameem Makhdoomi22 visualizações
Mechanics - Bar Of Uniform Strength por Sameem Makhdoomi
Mechanics - Bar Of Uniform StrengthMechanics - Bar Of Uniform Strength
Mechanics - Bar Of Uniform Strength
Sameem Makhdoomi73 visualizações
CAUCHY’S MEAN VALUE THEOREM por Sameem Makhdoomi
CAUCHY’S MEAN VALUE THEOREMCAUCHY’S MEAN VALUE THEOREM
CAUCHY’S MEAN VALUE THEOREM
Sameem Makhdoomi514 visualizações

Último

Sociology KS5 por
Sociology KS5Sociology KS5
Sociology KS5WestHatch
85 visualizações23 slides
Gross Anatomy of the Liver por
Gross Anatomy of the LiverGross Anatomy of the Liver
Gross Anatomy of the Liverobaje godwin sunday
61 visualizações12 slides
Relationship of psychology with other subjects. por
Relationship of psychology with other subjects.Relationship of psychology with other subjects.
Relationship of psychology with other subjects.palswagata2003
52 visualizações16 slides
Classification of crude drugs.pptx por
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptxGayatriPatra14
101 visualizações13 slides
Collective Bargaining and Understanding a Teacher Contract(16793704.1).pptx por
Collective Bargaining and Understanding a Teacher Contract(16793704.1).pptxCollective Bargaining and Understanding a Teacher Contract(16793704.1).pptx
Collective Bargaining and Understanding a Teacher Contract(16793704.1).pptxCenter for Integrated Training & Education
95 visualizações57 slides
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx por
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxEIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxISSIP
386 visualizações50 slides

Último(20)

Sociology KS5 por WestHatch
Sociology KS5Sociology KS5
Sociology KS5
WestHatch85 visualizações
Gross Anatomy of the Liver por obaje godwin sunday
Gross Anatomy of the LiverGross Anatomy of the Liver
Gross Anatomy of the Liver
obaje godwin sunday61 visualizações
Relationship of psychology with other subjects. por palswagata2003
Relationship of psychology with other subjects.Relationship of psychology with other subjects.
Relationship of psychology with other subjects.
palswagata200352 visualizações
Classification of crude drugs.pptx por GayatriPatra14
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptx
GayatriPatra14101 visualizações
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx por ISSIP
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxEIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
ISSIP386 visualizações
Monthly Information Session for MV Asterix (November) por Esquimalt MFRC
Monthly Information Session for MV Asterix (November)Monthly Information Session for MV Asterix (November)
Monthly Information Session for MV Asterix (November)
Esquimalt MFRC72 visualizações
The basics - information, data, technology and systems.pdf por JonathanCovena1
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdf
JonathanCovena1146 visualizações
Java Simplified: Understanding Programming Basics por Akshaj Vadakkath Joshy
Java Simplified: Understanding Programming BasicsJava Simplified: Understanding Programming Basics
Java Simplified: Understanding Programming Basics
Akshaj Vadakkath Joshy322 visualizações
Jibachha publishing Textbook.docx por DrJibachhaSahVetphys
Jibachha publishing Textbook.docxJibachha publishing Textbook.docx
Jibachha publishing Textbook.docx
DrJibachhaSahVetphys51 visualizações
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively por PECB
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
PECB 623 visualizações
Use of Probiotics in Aquaculture.pptx por AKSHAY MANDAL
Use of Probiotics in Aquaculture.pptxUse of Probiotics in Aquaculture.pptx
Use of Probiotics in Aquaculture.pptx
AKSHAY MANDAL119 visualizações
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptx por Debapriya Chakraborty
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptxGopal Chakraborty Memorial Quiz 2.0 Prelims.pptx
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptx
Debapriya Chakraborty695 visualizações
Solar System and Galaxies.pptx por DrHafizKosar
Solar System and Galaxies.pptxSolar System and Galaxies.pptx
Solar System and Galaxies.pptx
DrHafizKosar106 visualizações
S1_SD_Resources Walkthrough.pptx por LAZAROAREVALO1
S1_SD_Resources Walkthrough.pptxS1_SD_Resources Walkthrough.pptx
S1_SD_Resources Walkthrough.pptx
LAZAROAREVALO164 visualizações
Psychology KS5 por WestHatch
Psychology KS5Psychology KS5
Psychology KS5
WestHatch119 visualizações
When Sex Gets Complicated: Porn, Affairs, & Cybersex por Marlene Maheu
When Sex Gets Complicated: Porn, Affairs, & CybersexWhen Sex Gets Complicated: Porn, Affairs, & Cybersex
When Sex Gets Complicated: Porn, Affairs, & Cybersex
Marlene Maheu85 visualizações

Data Abstraction

  • 1. Object Oriented Programming in C++ Central University Of Kashmir Data Abstraction in C++ Presented by : Peerzada Sameem Makhdoomi Enrollment no. 2124CUKmr09
  • 2. • Data Abstraction is a programming technique that depends on the separation of the interface and implementation details of the program. • Data Abstraction is a process of providing only the essential details to the outside world and hiding the internal details i.e., representing only the essential details in the program. • let's take a real life example of AC, which can be turned ON or OFF, change the temperature, change the mode, and other external components such as fan, swing. But, we don't know the internal details of the AC, i.e., how it works internally. Thus, we can say that AC separates the implementation details from the external interface. • C++ provides a great level of abstraction. For example, pow() function is used to calculate the power of a number without knowing the algorithm the function follows. What is data abstraction ?
  • 3. Data Abstraction can be achievedin two ways:  Abstraction using classes  Abstraction in header files.  Abstraction using classes:- An abstraction can be achieved using classes. A class is used to group all the data members and member functions into a single unit by using the access specifiers. A class has the responsibility to determine which data member is to be visible outside and which is not.  Abstraction in header files:- An another type of abstraction is header file. For example, pow() function available is used to calculate the power of a number without actually knowing which algorithm function uses to calculate the power. Thus, we can say that header files hides all the implementation details from the user.
  • 4. Access Specifiers Implement Abstraction: In C++, we use access labels to define the abstract interface to the class. A class may contain zero or more access labels o Members defined with a public label are accessible to all parts of the program. The data-abstraction view of a type is defined by its public members. o Members defined with a private label are not accessible to code that uses the class. The private sections hide the implementation from code that uses the type
  • 5. Advantages of Data Abstraction:  Helps the user to avoid writing the low level code  Avoids code duplication and increases reusability.  Can change internal implementation of class independently without affecting the user.  Helps to increase security of an application or program as only important details are provided to the user.
  • 6. i. Abstraction separates code into interface and implementation. So while designing your component, you must keep interface independent of the implementation so that if you change underlying implementation then interface would remain intact. ii. In this case whatever programs are using these interfaces, they would not be impacted and would just need a recompilation with the latest implementation. Designing Strategy:
  • 7. Let's see a simple example of abstraction in header files. // Program to calculate the power of any number. #include <iostream> #include<math.h> using namespace std; int main( ) { int number , result , power = 3; cout<<“Enter any number:”<<endl; // for example 4 cin>>number; result = pow (number , power); // pow (number , power) is the power function cout << "Cube of the number is : "<<result<< endl; return 0; } Output: Cube of the number is : //64 In the above example, pow() function is used to calculate 4 raised to the power 3. The pow() function is present in the math.h header file in which all the implementation details of the pow() function is hidden.
  • 8. #include <iostream> using namespace std; class implementAbstraction{ private: int a, b; public: // method to set values of // private members void set(int x, int y) { a = x; b = y; } void display() { cout<<"a = " <<a << endl; cout<<"b = " << b << endl; } }; int main() { implementAbstraction obj; obj.set(10, 20); obj.display(); return 0; } example:
  • 9. Output: a = 10 b = 20  You can see in the above program we are not allowed to access the variables a and b directly, however one can call the function set() to set the values in a and b and the function display() to display the values of a and b.