SlideShare a Scribd company logo
1 of 17
Download to read offline
Object Oriented
Programming
Encapsulation
Group Members:
 Oman Mahmood
 Abdul Rehman
 Basit Ali
Objectives:
 What is Encapsulation?
 Why Encapsulation?
 Syntax
 Example
 Advantages and achievements
What is Encapsulation?
 "A language mechanism for restricting access to some of
the object's components"
 Encapsulation is the process of combining data and
functions into a single unit called class.
 Data is only accessible through the functions present
inside the class.
What is Encapsulation?
 Hiding the implementation details and providing
restrictive access leads to the concept of abstract data
type.
 Data encapsulation led to the important concept of data
hiding.
Why Encapsulation?
 "It gives us secure and consistence results".
Means that it gives the user access to a limited data and
keeps our valuable data which can change our program or
increase the possibilities of mistakes hidden from the
user.
 We can understand this more by this example:
Assume we made a Rectangle class that contained four
variables - length, width, area, and perimeter.
Why Encapsulation?
 Please note that area and perimeter are derived from
length and width, so that changing length would change
both area and perimeter. If you did not use proper
information hiding (encapsulation), then another
program utilizing that Rectangle class could alter the
length without altering the area, and you would have an
inconsistent Rectangle..
Why Encapsulation?
 Using encapsulation, we can create a function that, if a
program wanted to change the length of the rectangle,
that the object would appropriately update its area and
perimeter without being inconsistent.
 The ideal is to keep as many of the details of each class
hidden from all other classes as possible.
Syntax:
 The syntax of encapsulation is very easy, for
encapsulation we have to declare a class and then we
have to mark or tell in our program which data we want
to show and which we want to hide.
class Box
{
public:
double getVolume(void)
Syntax:
{
return length * breadth * height;
}
private:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
Example:
 We can understand it more by a C++ program
#include <iostream>
#include<stdlib.h>
using namespace std;
class Adder{
public:
Adder(int i = 0)
Example:
{
total = i;
}
// interface to outside world
void addNum(int number)
{
total += number;
}
int getTotal()
Example:
{
return total;
};
private: // This keeps our data hidden from the world
int total;
};
int main( )
{
systam("color A");
Adder a;
Example:
a.addNum(10);
a.addNum(20);
a.addNum(30);
cout << "Total " << a.getTotal() <<endl;
return 0;
}
Example:
 When the above code is compiled and executed, it
produces the following result :
Result is 60.
Advantages and Achievements
 Makes Maintenance of Application Easier.
 Improves the Understandability of the Application
 Enhanced Security

More Related Content

Similar to encapsulation1-150816163959-lva1-app6891.pdf

Similar to encapsulation1-150816163959-lva1-app6891.pdf (20)

Encapsulation in C++
Encapsulation in C++Encapsulation in C++
Encapsulation in C++
 
C++ with student management system project
C++ with student management system projectC++ with student management system project
C++ with student management system project
 
Oops
OopsOops
Oops
 
Abstraction
Abstraction Abstraction
Abstraction
 
Abstraction
AbstractionAbstraction
Abstraction
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Language
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
OOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptxOOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptx
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
OOP in java
OOP in javaOOP in java
OOP in java
 
concept of oops
concept of oopsconcept of oops
concept of oops
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
babsatu-140703233001-phpapp666666601.pdf
babsatu-140703233001-phpapp666666601.pdfbabsatu-140703233001-phpapp666666601.pdf
babsatu-140703233001-phpapp666666601.pdf
 
Bab satu
Bab satuBab satu
Bab satu
 
DTS s03e02 Handling the code
DTS s03e02 Handling the codeDTS s03e02 Handling the code
DTS s03e02 Handling the code
 
Oo Design And Patterns
Oo Design And PatternsOo Design And Patterns
Oo Design And Patterns
 
Java oop concepts
Java oop conceptsJava oop concepts
Java oop concepts
 
ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptx
 

More from kashafishfaq21

Registers.pptxmjgfdgjbgghjghjjfyujgftujbvf
Registers.pptxmjgfdgjbgghjghjjfyujgftujbvfRegisters.pptxmjgfdgjbgghjghjjfyujgftujbvf
Registers.pptxmjgfdgjbgghjghjjfyujgftujbvfkashafishfaq21
 
HAFIZA PP666666576887654678876544566T.pdf
HAFIZA  PP666666576887654678876544566T.pdfHAFIZA  PP666666576887654678876544566T.pdf
HAFIZA PP666666576887654678876544566T.pdfkashafishfaq21
 
circuits-150320014416-conversion-gate01.pdf
circuits-150320014416-conversion-gate01.pdfcircuits-150320014416-conversion-gate01.pdf
circuits-150320014416-conversion-gate01.pdfkashafishfaq21
 
inheritance-16031525566nbhij56604452.pdf
inheritance-16031525566nbhij56604452.pdfinheritance-16031525566nbhij56604452.pdf
inheritance-16031525566nbhij56604452.pdfkashafishfaq21
 
polymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdfpolymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdfkashafishfaq21
 
logicgates-180511113246666666660 (1).pdf
logicgates-180511113246666666660 (1).pdflogicgates-180511113246666666660 (1).pdf
logicgates-180511113246666666660 (1).pdfkashafishfaq21
 
ifrad01605545networkcomponents-181123160910.pdf
ifrad01605545networkcomponents-181123160910.pdfifrad01605545networkcomponents-181123160910.pdf
ifrad01605545networkcomponents-181123160910.pdfkashafishfaq21
 

More from kashafishfaq21 (7)

Registers.pptxmjgfdgjbgghjghjjfyujgftujbvf
Registers.pptxmjgfdgjbgghjghjjfyujgftujbvfRegisters.pptxmjgfdgjbgghjghjjfyujgftujbvf
Registers.pptxmjgfdgjbgghjghjjfyujgftujbvf
 
HAFIZA PP666666576887654678876544566T.pdf
HAFIZA  PP666666576887654678876544566T.pdfHAFIZA  PP666666576887654678876544566T.pdf
HAFIZA PP666666576887654678876544566T.pdf
 
circuits-150320014416-conversion-gate01.pdf
circuits-150320014416-conversion-gate01.pdfcircuits-150320014416-conversion-gate01.pdf
circuits-150320014416-conversion-gate01.pdf
 
inheritance-16031525566nbhij56604452.pdf
inheritance-16031525566nbhij56604452.pdfinheritance-16031525566nbhij56604452.pdf
inheritance-16031525566nbhij56604452.pdf
 
polymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdfpolymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdf
 
logicgates-180511113246666666660 (1).pdf
logicgates-180511113246666666660 (1).pdflogicgates-180511113246666666660 (1).pdf
logicgates-180511113246666666660 (1).pdf
 
ifrad01605545networkcomponents-181123160910.pdf
ifrad01605545networkcomponents-181123160910.pdfifrad01605545networkcomponents-181123160910.pdf
ifrad01605545networkcomponents-181123160910.pdf
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 

encapsulation1-150816163959-lva1-app6891.pdf

  • 1.
  • 3. Group Members:  Oman Mahmood  Abdul Rehman  Basit Ali
  • 4. Objectives:  What is Encapsulation?  Why Encapsulation?  Syntax  Example  Advantages and achievements
  • 5. What is Encapsulation?  "A language mechanism for restricting access to some of the object's components"  Encapsulation is the process of combining data and functions into a single unit called class.  Data is only accessible through the functions present inside the class.
  • 6. What is Encapsulation?  Hiding the implementation details and providing restrictive access leads to the concept of abstract data type.  Data encapsulation led to the important concept of data hiding.
  • 7. Why Encapsulation?  "It gives us secure and consistence results". Means that it gives the user access to a limited data and keeps our valuable data which can change our program or increase the possibilities of mistakes hidden from the user.  We can understand this more by this example: Assume we made a Rectangle class that contained four variables - length, width, area, and perimeter.
  • 8. Why Encapsulation?  Please note that area and perimeter are derived from length and width, so that changing length would change both area and perimeter. If you did not use proper information hiding (encapsulation), then another program utilizing that Rectangle class could alter the length without altering the area, and you would have an inconsistent Rectangle..
  • 9. Why Encapsulation?  Using encapsulation, we can create a function that, if a program wanted to change the length of the rectangle, that the object would appropriately update its area and perimeter without being inconsistent.  The ideal is to keep as many of the details of each class hidden from all other classes as possible.
  • 10. Syntax:  The syntax of encapsulation is very easy, for encapsulation we have to declare a class and then we have to mark or tell in our program which data we want to show and which we want to hide. class Box { public: double getVolume(void)
  • 11. Syntax: { return length * breadth * height; } private: double length; // Length of a box double breadth; // Breadth of a box double height; // Height of a box };
  • 12. Example:  We can understand it more by a C++ program #include <iostream> #include<stdlib.h> using namespace std; class Adder{ public: Adder(int i = 0)
  • 13. Example: { total = i; } // interface to outside world void addNum(int number) { total += number; } int getTotal()
  • 14. Example: { return total; }; private: // This keeps our data hidden from the world int total; }; int main( ) { systam("color A"); Adder a;
  • 16. Example:  When the above code is compiled and executed, it produces the following result : Result is 60.
  • 17. Advantages and Achievements  Makes Maintenance of Application Easier.  Improves the Understandability of the Application  Enhanced Security