SlideShare a Scribd company logo
4
Most read
6
Most read
7
Most read
THEORY OF PROGRAMMING LANGUAGES
Encapsulation & Inheritance
content
■ Explanation of Encapsulation and information hiding
■ General 3 different ways to Encapsulate data
■ Advantage of Encapsulation ( Information hiding )
ENCAPSULATION
“ to enclose in or as in a capsule ”
■ The object-oriented meaning of encapsulation is to enclose related data,
routines and definitions in a class capsule. This does not necessarily
mean hiding. (Mish)
■ Encapsulation is the ‘bundling together’ of data and behavior so that they
are inseparable. (Mcgraw Hill)
Why Encapsulation is also called information
hiding ?
■ Encapsulation (also called information hiding) consists of separating the external
aspects of an object, from the internal implementation details of the object, which are
hidden from other objects.
Information Hiding
1. The purpose of Information hiding is to make inaccessible certain details that should not
affect other parts of a system.
(Ross et al)
2. Information hiding is the principle that users of a software component (such as a class)
need to know only the essential details of how to initialize and access the component,
and do not need to know the details of the implementation. (Budd)
General 3 ways to Encapsulate Data
■ Public member access specifier
■ Private member access specifier
■ Protected member access specifier
Public member access specifier
■ A public member can be accessed by any function.
SYNTAX:
public: <declarations>
Private member access specifier
■ A private member can be accessed only by member functions and friends of the class in
which it is declared.
■ Class members are private by default.
SYNTAX:
private: <declarations>
Protected member access specifier
■ A protected member can be accessed by member functions and friends of the class in
which it was declared.
SYNTAX:
protected: <declarations>
For Example:
class MyClass
{
public: //access from anywhere
int x;
private: //only access from within a class
int y;
protected: //access from within a class ,or derived class
int z;
};
Advantage of Encapsulation ( Information
hiding )
1. It prevents others accessing the insides of an object.
The only thing that can manipulate the data in an object is that object’s method or member
function.
2. It main aim is to prevent accident.
It builds a protective wall (encapsulation) around the member data and member function of the
class, and hiding implementation details of object. So It keeps data safe from accident.
INHERITANCE
“the mechanism by which one class acquires
the properties of another class”
C++ and inheritance
■ The language mechanism by which one class acquires the properties (data and
operations) of another class.
■ Base Class (or superclass): the class being inherited from.
■ Derived Class (or subclass): the class that inherits
Advantages of
inheritance
When a class inherits from another class, there are three benefits:
■ You can reuse the methods and data of the existing class
■ You can extend the existing class by adding new data and new methods.
■ You can modify the existing class by overloading its methods with your own
implementations
Inheritance and
accessibility
■ A class inherits the behaviorof another class and enhances it in some way
■ Inheritance does not mean inheriting access to another class’ private members
■ Derived classes are special cases of base classes.
■ A derived class can also serve as a base class for new classes.
■ It is possible for a class to be a base class for more than one derived class .
Static vs. dynamic
binding
■ Static Binding:
Static binding occurs during the compile time.
■ Dynamic Binding:
Dynamic binding occurs during the run time.
Protected class
members
■ Derived classes cannot access the private data of the base class
■ Declaring methods and data of the base class as protected (instead of private)
allows derived classes to access them
■ Objects outside the class, however, cannot access them (same as private)
THANKYOU

More Related Content

What's hot (20)

PPTX
polymorphism
Imtiaz Hussain
 
PPTX
Cryptography by Durlab Kumbhakar
Durlove Kumbhakar
 
PPTX
UML constructs
Dawood Faheem Abbasi
 
PPTX
Lecture_7-Encapsulation in Java.pptx
ShahinAhmed49
 
PPTX
Chapter 07 inheritance
Praveen M Jigajinni
 
PPTX
Introduction to Mobile programming(J2ME)
Wambua Wambua
 
PPTX
Encapsulation
Burhan Ahmed
 
PPTX
Inheritance in oops
Hirra Sultan
 
PPT
Oop Presentation
Ghaffar Khan
 
PDF
Object oriented programming interview questions
Keet Sugathadasa
 
PPTX
Polymorphism In c++
Vishesh Jha
 
PPTX
Encapsulation
saikat rahman
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
Abstraction in java.pptx
AsifMulani17
 
PDF
Introduction to oops concepts
Nilesh Dalvi
 
PPT
Encapsulation
FALLEE31188
 
PPTX
Properties and indexers in C#
Hemant Chetwani
 
PPTX
[OOP - Lec 08] Encapsulation (Information Hiding)
Muhammad Hammad Waseem
 
PDF
Rail Fence Cryptography in Securing Information
Universitas Pembangunan Panca Budi
 
PPTX
THE PACKAGES CONCEPT IN JAVA PROGRAMMING.pptx
Kavitha713564
 
polymorphism
Imtiaz Hussain
 
Cryptography by Durlab Kumbhakar
Durlove Kumbhakar
 
UML constructs
Dawood Faheem Abbasi
 
Lecture_7-Encapsulation in Java.pptx
ShahinAhmed49
 
Chapter 07 inheritance
Praveen M Jigajinni
 
Introduction to Mobile programming(J2ME)
Wambua Wambua
 
Encapsulation
Burhan Ahmed
 
Inheritance in oops
Hirra Sultan
 
Oop Presentation
Ghaffar Khan
 
Object oriented programming interview questions
Keet Sugathadasa
 
Polymorphism In c++
Vishesh Jha
 
Encapsulation
saikat rahman
 
Classes, objects in JAVA
Abhilash Nair
 
Abstraction in java.pptx
AsifMulani17
 
Introduction to oops concepts
Nilesh Dalvi
 
Encapsulation
FALLEE31188
 
Properties and indexers in C#
Hemant Chetwani
 
[OOP - Lec 08] Encapsulation (Information Hiding)
Muhammad Hammad Waseem
 
Rail Fence Cryptography in Securing Information
Universitas Pembangunan Panca Budi
 
THE PACKAGES CONCEPT IN JAVA PROGRAMMING.pptx
Kavitha713564
 

Similar to Encapsulation and inheritance (20)

PPTX
Presentation related to Encapsulation and OOPs
vinitsinghthakur46
 
PPTX
Presentation - Copy no vaperpoit asd.pptx
RajshreePathir
 
PPTX
Presen5416846534653416354165341864adeadvdes
RajshreePathir
 
PPTX
Prese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptx
RajshreePathir
 
PPTX
Prese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptx
RajshreePathir
 
PPTX
Encapsulation C++ Piller of OOP it is the important piller
an7539661
 
PPTX
Encapsulation C++ Piller of OOP it is the important piller
an7539661
 
PPT
C++Presentation 2.PPT
VENARATEKANHURU
 
PPTX
ENCAPSULATION module for IT or comsci.pptx
MattFlordeliza1
 
PPTX
Module 4 Effect of Reuse on using Encapsulation.pptx
ramlingams
 
PPTX
004_Private and public attributes and methods.pptx
MarioCaday2
 
PPTX
27csharp
Sireesh K
 
PPTX
27c
Sireesh K
 
PPT
Classes and objects
Lovely Professional University
 
PPTX
Opp concept in c++
SadiqullahGhani1
 
PPTX
Object Oriented Programming
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Inheritance, Object Oriented Programming
Arslan Waseem
 
PPTX
Unit-4 Day1.pptx
Revathiparamanathan
 
PDF
C++ Notes
MOHAMED RIYAZUDEEN
 
PPTX
java part 1 computer science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Presentation related to Encapsulation and OOPs
vinitsinghthakur46
 
Presentation - Copy no vaperpoit asd.pptx
RajshreePathir
 
Presen5416846534653416354165341864adeadvdes
RajshreePathir
 
Prese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptx
RajshreePathir
 
Prese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptx
RajshreePathir
 
Encapsulation C++ Piller of OOP it is the important piller
an7539661
 
Encapsulation C++ Piller of OOP it is the important piller
an7539661
 
C++Presentation 2.PPT
VENARATEKANHURU
 
ENCAPSULATION module for IT or comsci.pptx
MattFlordeliza1
 
Module 4 Effect of Reuse on using Encapsulation.pptx
ramlingams
 
004_Private and public attributes and methods.pptx
MarioCaday2
 
27csharp
Sireesh K
 
Classes and objects
Lovely Professional University
 
Opp concept in c++
SadiqullahGhani1
 
Inheritance, Object Oriented Programming
Arslan Waseem
 
Unit-4 Day1.pptx
Revathiparamanathan
 
java part 1 computer science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Ad

Recently uploaded (20)

PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Ad

Encapsulation and inheritance

  • 3. content ■ Explanation of Encapsulation and information hiding ■ General 3 different ways to Encapsulate data ■ Advantage of Encapsulation ( Information hiding )
  • 4. ENCAPSULATION “ to enclose in or as in a capsule ” ■ The object-oriented meaning of encapsulation is to enclose related data, routines and definitions in a class capsule. This does not necessarily mean hiding. (Mish) ■ Encapsulation is the ‘bundling together’ of data and behavior so that they are inseparable. (Mcgraw Hill)
  • 5. Why Encapsulation is also called information hiding ? ■ Encapsulation (also called information hiding) consists of separating the external aspects of an object, from the internal implementation details of the object, which are hidden from other objects.
  • 6. Information Hiding 1. The purpose of Information hiding is to make inaccessible certain details that should not affect other parts of a system. (Ross et al) 2. Information hiding is the principle that users of a software component (such as a class) need to know only the essential details of how to initialize and access the component, and do not need to know the details of the implementation. (Budd)
  • 7. General 3 ways to Encapsulate Data ■ Public member access specifier ■ Private member access specifier ■ Protected member access specifier
  • 8. Public member access specifier ■ A public member can be accessed by any function. SYNTAX: public: <declarations>
  • 9. Private member access specifier ■ A private member can be accessed only by member functions and friends of the class in which it is declared. ■ Class members are private by default. SYNTAX: private: <declarations>
  • 10. Protected member access specifier ■ A protected member can be accessed by member functions and friends of the class in which it was declared. SYNTAX: protected: <declarations>
  • 11. For Example: class MyClass { public: //access from anywhere int x; private: //only access from within a class int y; protected: //access from within a class ,or derived class int z; };
  • 12. Advantage of Encapsulation ( Information hiding ) 1. It prevents others accessing the insides of an object. The only thing that can manipulate the data in an object is that object’s method or member function. 2. It main aim is to prevent accident. It builds a protective wall (encapsulation) around the member data and member function of the class, and hiding implementation details of object. So It keeps data safe from accident.
  • 13. INHERITANCE “the mechanism by which one class acquires the properties of another class”
  • 14. C++ and inheritance ■ The language mechanism by which one class acquires the properties (data and operations) of another class. ■ Base Class (or superclass): the class being inherited from. ■ Derived Class (or subclass): the class that inherits
  • 15. Advantages of inheritance When a class inherits from another class, there are three benefits: ■ You can reuse the methods and data of the existing class ■ You can extend the existing class by adding new data and new methods. ■ You can modify the existing class by overloading its methods with your own implementations
  • 16. Inheritance and accessibility ■ A class inherits the behaviorof another class and enhances it in some way ■ Inheritance does not mean inheriting access to another class’ private members
  • 17. ■ Derived classes are special cases of base classes. ■ A derived class can also serve as a base class for new classes. ■ It is possible for a class to be a base class for more than one derived class .
  • 18. Static vs. dynamic binding ■ Static Binding: Static binding occurs during the compile time. ■ Dynamic Binding: Dynamic binding occurs during the run time.
  • 19. Protected class members ■ Derived classes cannot access the private data of the base class ■ Declaring methods and data of the base class as protected (instead of private) allows derived classes to access them ■ Objects outside the class, however, cannot access them (same as private)