SlideShare a Scribd company logo
1 of 10
Download to read offline
Chapter 2

Encapsulation

Dyah Fajar Nur Rohmah
Introduction
Encaptulation is the technique of making the fields
in a class private and providing access to the fields
via public methods.

Encapsulation also can be described as a protective
barrier that prevents the code and data being

randomly accessed by other code defined outside
the class.
Why need encapsulation?
Combining data and how it's manipulated in one
place: This is achieved through the state (the
private fields) and the behaviors (the public
methods) of an object.

Only allowing the state of an object to be accessed
and modified through behaviors: The values

contained within an object's state can then be
strictly controlled.
Why need encapsulation? (cont.. )
Hiding the details of how the object works: The
only part of the object that is accessible to the

outside world is its behaviors. What happens inside
those behaviors and how the state is stored is
hidden from view.

public functions

private
functions

private data
Maintainability
Encapsulation draws a boundary around a set of
data and method.

This allows a developer to use the code without

having to know how it works, but with what input
data and its input data range and with what it
returns.
Flexibility
Encapsulation makes the code easier to visualize.

This means codes can be arranged “visually” before
implementing.
Extensibility
Makes long term development easy.

Updates can be made by changing the

encapsulated part without changing the input and
output formats.
Kesimpulan
Encapsulation is the technique of making the fields

in a class private and providing access to the fields
via public methods.

The main benefit of encapsulation is the ability to
modify the implemented code without breaking

the code of others who use the implemented code.
Kesimpulan (cont.. .)
Encapsulation makes the programing code:

Flexi
ble

Main
taina
ble

Exte
nsibl
e
Thank You

Reference from:
Githushan Gengaparam - Madhusoothanan
Lakshitha Imbulpitiya - Sudheera Karunaratne

More Related Content

What's hot

What's hot (20)

Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
2CPP09 - Encapsulation
2CPP09 - Encapsulation2CPP09 - Encapsulation
2CPP09 - Encapsulation
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4
 
C# Encapsulation
C# EncapsulationC# Encapsulation
C# Encapsulation
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
 
Python-Encapsulation.pptx
Python-Encapsulation.pptxPython-Encapsulation.pptx
Python-Encapsulation.pptx
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Java IO
Java IOJava IO
Java IO
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
concept of oops
concept of oopsconcept of oops
concept of oops
 

Similar to Chapter2 Encapsulation (Java)

"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”
IOSR Journals
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
vamshimahi
 
Booa8 Slide 07
Booa8 Slide 07Booa8 Slide 07
Booa8 Slide 07
oswchavez
 
Java interview faq's
Java interview faq'sJava interview faq's
Java interview faq's
Deepak Raj
 

Similar to Chapter2 Encapsulation (Java) (20)

Encapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important pillerEncapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important piller
 
Encapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important pillerEncapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important piller
 
"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”
 
What is clear to you about OOP in Java- and what concepts are still cl.docx
What is clear to you about OOP in Java- and what concepts are still cl.docxWhat is clear to you about OOP in Java- and what concepts are still cl.docx
What is clear to you about OOP in Java- and what concepts are still cl.docx
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
data abstraction ,encapsulation,A.D.T
data abstraction ,encapsulation,A.D.Tdata abstraction ,encapsulation,A.D.T
data abstraction ,encapsulation,A.D.T
 
Encapsulation and inheritance
Encapsulation and inheritanceEncapsulation and inheritance
Encapsulation and inheritance
 
Booa8 Slide 07
Booa8 Slide 07Booa8 Slide 07
Booa8 Slide 07
 
Java chapter 3
Java   chapter 3Java   chapter 3
Java chapter 3
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
Benefits of encapsulation
Benefits of encapsulationBenefits of encapsulation
Benefits of encapsulation
 
Java interview faq's
Java interview faq'sJava interview faq's
Java interview faq's
 
Object oriented programming concept
Object oriented programming conceptObject oriented programming concept
Object oriented programming concept
 
Lecture 2 cst 205-281 oop
Lecture 2   cst 205-281 oopLecture 2   cst 205-281 oop
Lecture 2 cst 205-281 oop
 
Distributed database security with discretionary access control
Distributed database security with discretionary access controlDistributed database security with discretionary access control
Distributed database security with discretionary access control
 
OOP_presentation.pptx
OOP_presentation.pptxOOP_presentation.pptx
OOP_presentation.pptx
 
Lecture #4: Access Control Policies
Lecture #4: Access Control PoliciesLecture #4: Access Control Policies
Lecture #4: Access Control Policies
 
OOP presentation.pptx
OOP presentation.pptxOOP presentation.pptx
OOP presentation.pptx
 
Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
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
QucHHunhnh
 

Recently uploaded (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
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
 

Chapter2 Encapsulation (Java)

  • 2. Introduction Encaptulation is the technique of making the fields in a class private and providing access to the fields via public methods. Encapsulation also can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class.
  • 3. Why need encapsulation? Combining data and how it's manipulated in one place: This is achieved through the state (the private fields) and the behaviors (the public methods) of an object. Only allowing the state of an object to be accessed and modified through behaviors: The values contained within an object's state can then be strictly controlled.
  • 4. Why need encapsulation? (cont.. ) Hiding the details of how the object works: The only part of the object that is accessible to the outside world is its behaviors. What happens inside those behaviors and how the state is stored is hidden from view. public functions private functions private data
  • 5. Maintainability Encapsulation draws a boundary around a set of data and method. This allows a developer to use the code without having to know how it works, but with what input data and its input data range and with what it returns.
  • 6. Flexibility Encapsulation makes the code easier to visualize. This means codes can be arranged “visually” before implementing.
  • 7. Extensibility Makes long term development easy. Updates can be made by changing the encapsulated part without changing the input and output formats.
  • 8. Kesimpulan Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. The main benefit of encapsulation is the ability to modify the implemented code without breaking the code of others who use the implemented code.
  • 9. Kesimpulan (cont.. .) Encapsulation makes the programing code: Flexi ble Main taina ble Exte nsibl e
  • 10. Thank You Reference from: Githushan Gengaparam - Madhusoothanan Lakshitha Imbulpitiya - Sudheera Karunaratne